Mysql 如何仅获取当前年度?

Mysql 如何仅获取当前年度?,mysql,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) 样本输出 我只想展示

我有这个查询,我只想得到今年的数据

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年。如何做到这一点?

如果我理解正确,您可以尝试以下方法:

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

尝试以下操作:

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)

我的意思是我想在输出中得到当前年份,应该是2019年1月、2019年2月、2019年3月、2019年7月。然后只需添加where条款来限制2019年