查找一个月内不同工人的数量

时间:2017-03-24 21:28:43

标签: mysql date select

鉴于下一个表格:

MonthYear          Name        Mission
-------------------------------------------
August 2016        Joe        Clean Table
August 2016        Joe        Clean Door
August 2016        Charles    Clean Table
September 2016     Joe        Clean Dorm
September 2016     Charles    Clean Kitchen
September 2016     Charles    Clean Roof
October 2016       Dominique  Clean Kitchen
October 2016       Dominique  Clean table

我需要知道每个月工作的人数。所以,我需要生成下一个表:

MonthYear                Number of Workers
-----------------------------------
August 2016               2
September 2016            2
October 2016              1

1 个答案:

答案 0 :(得分:2)

基本上按MonthYear分组并计算不同的工人。

select   MonthYear, count(distinct Name) as NumberOfWorkers
from     your_table
group by MontYear;