我想按组织统计老师,组织者,管理员小组。
这是我当前的数据库示例:
预期结果将是:
teacher | organizer | administrator | organization_id
---------------------------------------------------
1 | 1 | 1 | 6035
5 | 4 | 1 | 12554
到目前为止我尝试了什么
SELECT
count(teacher),
count(organizer),
count(administrator),
organization_id
FROM users
WHERE
teacher = 1
AND organizer = 1
AND administrator = 1
GROUP BY organization_id;
答案 0 :(得分:1)
因为您的列值为0/1,因此您只需使用SUM
来计算nums:
SELECT
SUM(teacher) as teacher,
SUM(organizer) as organizer,
SUM(administrator)as administrator,
organization_id
FROM users GROUP BY organization_id
答案 1 :(得分:0)
根据您的预期结果,我认为您应该在AddType image/svg+xml svg
AddType image/svg+xml svgz
声明中使用or
而不是and
。
where