按DISTINCT计数表

时间:2019-10-28 17:02:06

标签: html

所以我的桌子上有这样的记录

ID    Department

1     Finance
2     Engineering
3     IT
4     Finance
5     IT
6     IT

我应该能够得到:

Count Department
3     IT
2     Finance
1     Engineering

有什么想法吗?

谢谢

1 个答案:

答案 0 :(得分:1)

使用WHERE限制行。

SELECT id, 1 AS valid, Department
FROM RECORDS
WHERE DATEDIFF(quitDate, hiredDate) < 730 AND Department = 'IT'