我有此查询,我只想获取当前年份,
SELECT DATE_FORMAT(in_time,'%M %Y') as MonthlyAtt,
count(employees_id) as AttCount,
count(Distinct employees_id) as DistinctedAttCount
FROM attendance
GROUP BY DATE_FORMAT(in_time,'%M %Y')
ORDER BY (in_time)
样本输出
我只想显示2019年。我该怎么办?
答案 0 :(得分:0)
如果我理解正确,则可以尝试以下操作:
SELECT DATE_FORMAT(in_time,'%M %Y') as MonthlyAtt,
count(employees_id) as AttCount,
count(Distinct employees_id) as DistinctedAttCount
FROM attendance
WHERE DATE_FORMAT(in_time,'%Y')=2019
GROUP BY DATE_FORMAT(in_time,'%M %Y')
ORDER BY DATE_FORMAT(in_time,'%M %Y') desc
使用where子句将搜索限制为仅2019年
答案 1 :(得分:0)
尝试一下:
SELECT DATE_FORMAT(in_time,'%M %Y') as MonthlyAtt,
count(employees_id) as AttCount,
count(Distinct employees_id) as DistinctedAttCount
FROM attendance
WHERE YEAR(in_time) = YEAR(CURDATE())
ORDER BY (in_time)