每:
COUNT(CASE WHEN b.name="Clase X" THEN b.name END)
在您的代码中,可以编写为:
SUM(b.name='Clase X')
b.name='Clase 1'
1
(对)或
0
(错误)。
false
如果是的话
或
true
0
.
所以你可以这样写你的查询:
SELECT concat_ws(' ', U.firstname, U.lastname) Nombre_Completo,
CASE WHEN SUM(b.name='Clase 1') THEN 'yes' ELSE 'no' END Clase1,
CASE WHEN SUM(b.name='Clase 2') THEN 'yes' ELSE 'no' END Clase2,
CASE WHEN SUM(b.name='Clase 3') THEN 'yes' ELSE 'no' END Clase3,
CASE WHEN SUM(b.name='Clase 4') THEN 'yes' ELSE 'no' END Clase4,
CASE WHEN SUM(b.name='Clase 5') THEN 'yes' ELSE 'no' END Clase5,
CASE WHEN SUM(b.name='Clase 6') THEN 'yes' ELSE 'no' END Clase6,
CASE WHEN SUM(b.name='Clase 7') THEN 'yes' ELSE 'no' END Clase7,
CASE WHEN SUM(b.name='Clase 8') THEN 'yes' ELSE 'no' END Clase8,
CASE WHEN SUM(b.name='Clase 9') THEN 'yes' ELSE 'no' END Clase9,
CASE WHEN SUM(b.name='Clase 10') THEN 'yes' ELSE 'no' END Clase10,
CASE WHEN SUM(b.name='Clase 11') THEN 'yes' ELSE 'no' END Clase11,
CASE WHEN SUM(b.name='Clase 12') THEN 'yes' ELSE 'no' END Clase12
FROM mdl_logstore_standard_log as L
LEFT JOIN mdl_course as C ON L.courseid = C.id
left JOIN mdl_user as U on L.userid = U.ID
JOIN mdl_bigbluebuttonbn AS b ON L.objectid = b.id
JOIN mdl_role_assignments AS ra ON L.userid = ra.userid
JOIN mdl_role AS r ON r.id = ra.roleid
WHERE (C.shortname LIKE '%CSG012020%') AND (ra.roleid=5) AND (ra.roleid NOT IN (3,4))
GROUP BY Nombre_Completo;
DISTINCT
因为你不需要它
GROUP BY Nombre_Completo
.