This query has been tested in Access 2010:
SELECT Team, Count(Date_Played) AS Count
FROM
(
SELECT DISTINCT Team, Date_Played
FROM NBAGameLog
) AS whatever
GROUP BY Team
Вопрос
My table in this issue has three columns: Player, Team and Date_Played.
Player Team Date_Played
John Smith New York 2/25/2014
Joe Smith New York 2/25/2014
Steve Johnson New York 2/25/2014
Steph Curry Orlando 2/25/2014
Frank Anthony Orlando 2/26/2014
Brian Smith New York 2/26/2014
Steve Johnson New York 2/27/2014
Steph Curry New York 2/28/2014
I know how to get a list of distinct team names or dates played, but what I'm looking for is a query that will group by Team and count the number of distinct Team & Date combinations. So the output should look like this:
Team Count
New York 4
Orlando 2
So far I have:
SELECT DISTINCT Tm, Count(Date_Played) AS Count
FROM NBAGameLog
GROUP BY NBAGameLog.[Tm];
But this gives me the total amount of records grouped by date.
Решение 2
This query has been tested in Access 2010:
SELECT Team, Count(Date_Played) AS Count
FROM
(
SELECT DISTINCT Team, Date_Played
FROM NBAGameLog
) AS whatever
GROUP BY Team
Другие советы
A bit less code:
SELECT Team, Count(distinct Date_Played) AS Count
FROM NBAGameLog
GROUP BY Team
It does Show the same execution plan as the first answer.
If I've understood right you, you are looking for a query like this:
SELECT x.Team, count(*)
FROM
(SELECT Team, Date_Played
FROM NBAGameLog
GROUP BY Team, Date_Played) AS x
GROUP BY x.Team