我对 SQL 相当陌生,但我被困在一个查询中。我有下表称为Appointment
NAME SERVICE DATE
-----------------------------
John Abc 2012-11-10
Michael Xyz 2012-11-10
Denis Xyz 2012-11-10
Denis Pqr 2012-11-06
John Abc 2012-11-06
Michael Abc 2012-11-05
Sofy Abc 2012-11-04
John Pqr 2012-11-01
Michael Pqr 2012-11-01
Michael Abc 2012-10-21
John Abc 2012-10-23
John HFD 2012-10-23
John BHU 2012-11-09
Michael KSD 2012-11-08
我想要做的是计算日期2012-11-01
和2012-11-10
.
以下是所需的输出
NAME Abc Pqr Xyz
--------------------------------
John 2 1 0
Michael 1 1 1
Denis 0 1 1
Sofy 1 0 0
这是我尝试过的:
SELECT Name, COUNT(Distinct Service)
FROM [Appointment]
WHERE [DATE] between '2012-11-01 00:00:00.000' and '2012-11-10 23:59:59.999'
AND (Service = 'Abc' or Service = 'Pqr' or Service = 'Xyz')
GROUP BY Name
先感谢您。