Reputation: 77
I have details of the count of users and the month in the 2nd column and the teams name in the 3rd columns as below. I want the o/p to give the sum of the users column for 7th, 8th and 9th month grouped w.r.t the month.
Count_of_Users Month Team
----------------------------
1 7 a
1 8 a
1 9 a
1 7 a
1 8 a
1 9 a
1 7 a
1 8 a
1 9 a
Query:
SELECT
(COUNT(DISTINCT([username]))) AS A,
MONTH([Date]) AS B,
Team
FROM
myTable
GROUP BY
[UserName], MONTH([Date]), Team
ORDER BY
[UserName], MONTH([Date]), Team
This is the query i had for the above o/p. I am not sure if i should be using UNION ALL
to proceed. Any inputs are appreciated.
Upvotes: 1
Views: 60
Reputation: 1269773
I'm not sure what you want, but your current version doesn't seem very useful. Is this what you intend?
SELECT COUNT(DISTINCT [username]) AS A,
MONTH([Date]) AS B,
Team
FROM myTable
GROUP BY MONTH([Date]), Team
ORDER BY MONTH([Date]), Team
Upvotes: 2