好的,这是我的数据集
Event_ID | WorkerNumberID
3 | Worker1
3 | Worker2
3 | Worker2
3 | Worker3
5 | Worker4
5 | Worker5
3 | Null
5 | Null
我希望我的查询返回以下内容。即使eventID 3有2个'worker2',我仍然只想将它计为1个非空项,因为它们是相同的。
Event_ID | WorkerNumberIDCount (a count of not null items)
3 | 3
5 | 2
思想?
答案 0 :(得分:2)
试试这个
SELECT Event_ID,COUNT(DISTINCT WorkerNumberID) AS WorkerNumberIDCount
FROM TableName
WHERE WorkerNumberID IS NOT NULL
Group By Event_ID