鉴于下一个表格:
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
答案 0 :(得分:2)
基本上按MonthYear分组并计算不同的工人。
select MonthYear, count(distinct Name) as NumberOfWorkers
from your_table
group by MontYear;