SUM(CASE WHEN m.graduation_time is not null and m.graduation_time <= now() and m.category = 1 THEN 1 ELSE 0 END) AS `by`,
SUM(CASE WHEN m.graduation_time is not null and m.graduation_time <= now() and m.category = 1 and m.qualification = 5 THEN 1 ELSE 0 END) AS `bySs`,
SUM(CASE WHEN m.graduation_time is not null and m.graduation_time <= now() and m.category = 1 and m.qualification = 6 THEN 1 ELSE 0 END) AS `byBs`,
SUM(CASE WHEN m.graduation_time is not null and m.graduation_time <= now() and m.category = 1 and m.qualification = 7 THEN 1 ELSE 0 END) AS `byBsh`,
SUM(CASE WHEN m.graduation_time is not null and m.graduation_time > now() and m.category = 1 THEN 1 ELSE 0 END) AS zd,
SUM(CASE WHEN m.graduation_time is not null and m.graduation_time > now() and m.category = 1 and m.qualification = 5 THEN 1 ELSE 0 END) AS zdSs,
SUM(CASE WHEN m.graduation_time is not null and m.graduation_time > now() and m.category = 1 and m.qualification = 6 THEN 1 ELSE 0 END) AS zdBs,
SUM(CASE WHEN m.graduation_time is not null and m.graduation_time > now() and m.category = 1 and m.qualification = 7 THEN 1 ELSE 0 END) AS zdBsh
SUM(CASE WHEN (m.graduation_time <= now()) and m.category = 1 THEN 1 ELSE 0 END) AS `by`,
SUM(CASE WHEN ((m.graduation_time <= now())) and m.category = 1 and m.reading_status = 0 THEN 1 ELSE 0 END) AS `bySs`,
SUM(CASE WHEN ((m.graduation_time <= now())) and m.category = 1 and m.reading_status = 1 THEN 1 ELSE 0 END) AS `byBs`,
SUM(CASE WHEN ((m.graduation_time <= now())) and m.category = 1 and m.reading_status = 2 THEN 1 ELSE 0 END) AS `byBsh`,
SUM(CASE WHEN (m.graduation_time is null or (m.graduation_time > now())) and m.category = 1 THEN 1 ELSE 0 END) AS zd,
SUM(CASE WHEN (m.graduation_time is null or (m.graduation_time > now())) and m.category = 1 and m.reading_status = 0 THEN 1 ELSE 0 END) AS zdSs,
SUM(CASE WHEN (m.graduation_time is null or (m.graduation_time > now())) and m.category = 1 and m.reading_status = 1 THEN 1 ELSE 0 END) AS zdBs,
SUM(CASE WHEN (m.graduation_time is null or (m.graduation_time > now())) and m.category = 1 and m.reading_status = 2 THEN 1 ELSE 0 END) AS zdBsh
from prj_proj_org o
left join
kts_kt_group g on g.proj_org_id = o.id and g.del_flag = 0
LEFT JOIN kts_kt_group_member m on m.kt_group_id = g.id
where o.del_flag = 0
LEFT JOIN kts_kt_group_member m on m.kt_group_id = g.id and m.category = 1
where o.del_flag = 0 and m.del_flag = 0 and g.del_flag = 0