仅如何获取当前年份?

时间:2019-07-16 06:18:44

标签: mysql

我有此查询,我只想获取当前年份,

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)

样本输出

Output of the Query Above

我只想显示2019年。我该怎么办?

2 个答案:

答案 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)