I have a MEMBERS
table with the following relevant columns:
Name
JoinDate
Level --1=Gold,2=Silver,3=Bronze**
I want to create a single query to return a membership summary that lists the total number who joined by year and by membership level. Basically, the columns in my resultset would be something like this:
| YEAR | GOLD | SILVER | BRONZE | TOTAL |
I could get the different counts per year for Gold, Silver and Bronze members respectively using the following 3 queries:
SELECT YEAR(JoinDate) AS YEAR, COUNT(*) AS GOLD FROM Members
WHERE Level=1 GROUP BY YEAR(JoinDate) ORDER BY YEAR(JoinDate)
SELECT YEAR(JoinDate) AS YEAR, COUNT(*) AS SILVER FROM Members
WHERE Level=2 GROUP BY YEAR(JoinDate) ORDER BY YEAR(JoinDate)
SELECT YEAR(JoinDate) AS YEAR, COUNT(*) AS BRONZE FROM Members
WHERE Level=3 GROUP BY YEAR(JoinDate) ORDER BY YEAR(JoinDate)
I could also get the totals using a similar query:
SELECT YEAR(JoinDate) AS YEAR, COUNT(*) AS TOTAL FROM Members
GROUP BY YEAR(JoinDate) ORDER BY YEAR(JoinDate)
My problem is I haven't found a way to simplify all these into a single query. How is this done?