gpt4 book ai didi

mysql - 需要缺席和出席人数以及月份名称

转载 作者:行者123 更新时间:2023-11-28 23:57:35 25 4
gpt4 key购买 nike

我需要一个带有缺席和在场计数的月份名称。这是我的数据库查询:

SELECT sid,COUNT(CASE WHEN STATUS ='A' THEN 1 END) AS absent_count,COUNT(CASE WHEN STATUS ='P' THEN 1 END) AS present_count,
MONTHNAME(attendance_date) AS `Month_Name`
FROM attendance
WHERE SID = '2'
AND campus_id = 2
GROUP BY sid;

最佳答案

group by sid 没有意义 - 根据您的 where 子句,它始终是 '2'。相反,由于您要计算每个月的名称,因此它应该出现在 group by 子句中:

SELECT   MONTHNAME(attendance_date) AS `Month_Name`, 
COUNT(CASE WHEN STATUS ='A' THEN 1 END) AS absent_count,
COUNT(CASE WHEN STATUS ='P' THEN 1 END) AS present_count,
FROM attendance
WHERE sid = '2' AND campus_id = 2
GROUP BY MONTHNAME(attendance_date);

关于mysql - 需要缺席和出席人数以及月份名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31177372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com