一些简单sql
时间:2022-03-15 01:26
SELECT
count(0) as totalNum,
sum(CASE WHEN learn_status = ‘1‘ AND subject_type = ‘3‘ AND STATUS = ‘1‘ THEN 1 ELSE 0 END) AS km1,
sum(CASE WHEN learn_status = ‘1‘ AND subject_type = ‘4‘ AND STATUS = ‘1‘ THEN 1 ELSE 0 END) AS km2,
sum(CASE WHEN learn_status = ‘1‘ AND subject_type = ‘5‘ AND STATUS = ‘1‘ THEN 1 ELSE 0 END) AS km3,
sum(CASE WHEN learn_status = ‘1‘ AND subject_type = ‘6‘ AND STATUS = ‘1‘ THEN 1 ELSE 0 END) AS km4
FROM
sm_student t
WHERE 1 = 1 AND school_id =1
按照学校找到科目3,4,5,6汇总的人数