1
回答
高手看过来看过来,想要一段高效sql
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

针对上面的报表 .求一段高效sql.. 欢迎高手参与..

------------------------------

我个人的sql是这样的. 省掉了 高2高三的 班级统计.  

SELECT  school.xxmc,COUNT (DISTINCT student.bj) AS grad_sum, COUNT(1)  AS person_sum, COUNT(1)/COUNT (DISTINCT student.bj) AS grad_hum_sum,
SUM(CASE  WHEN student.nj='31' THEN  1 ELSE  0 END ) AS grad1_stucount,
COUNT(DISTINCT gard1.bj)   AS grad1_count ,
SUM(CASE  WHEN student.nj='32' THEN  1 ELSE  0 END ) AS grad2_stucount,
SUM(CASE  WHEN student.nj='33' THEN  1 ELSE  0 END ) AS grad3_stucount
 FROM 
   tc_studentinfo student ,tc_schoolinfo  school ,
   (SELECT s.xxid,s.bj,s.nj  FROM  tc_studentinfo s ,tc_schoolinfo  c  WHERE s.xxid=c.xxid  AND  c.xxxz='05' AND s.nj='31') gard1
WHERE student.xxid=school.xxid(+)
AND  student.xxid=gard1.xxid(+)
AND  school.xxxz='05'  --    表示高中学段.     nj   {31,32,33}  表示  高一高二高三
   GROUP  BY student.xxid ,school.xxmc ;


<无标签>
举报
calvary
发帖于4年前 1回/147阅
顶部