This is the query I'm using to count how many events are booked for each category of bookings.
SELECT
Categories.name,
count(case when locations.name ='loc 1' then 1 end) as Location1,
count(case when locations.name ='loc 2' then 1 end) as Location2,
count(case when locations.name ='loc 3' then 1 end) as Location3,
count(Categories.name) as total
FROM
...
group by Categories.name
with rollup
This gives me the following result:
+------------------------------------------------------------+
|Category_name | Location1 | Location2 | Location3 | Total |
+------------------------------------------------------------+
|Cat1 | 1 | 2 | 2 | 5 |
|Cat2 | 2 | 1 | 2 | 5 |
|Cat3 | 2 | 2 | 2 | 6 |
|Cat3(Extra) | 1 | 3 | 2 | 6 |
|Cat4 | 3 | 1 | 2 | 6 |
+------------------------------------------------------------+
|Total per loc | 9 | 9 | 10 | 28 |
+------------------------------------------------------------+
This was satisfactory until now! Now I need to do the same request but I think I need to change the group by (??). Is there a way to change my request to this :
Count for Cat1 the number of events per location.
Count for Cat2 the number of events per location.
Count for Cat3 and Cat3(extra) the number of events per location.
Count for Cat4 the number of events per location.
What I mean is some Categories need to be counted together and what I'm looking to achieve is this result :
+------------------------------------------------------------+
|Category_name | Location1 | Location2 | Location3 | Total |
+------------------------------------------------------------+
|Cat1 | 1 | 2 | 2 | 5 |
|Cat2 | 2 | 1 | 2 | 5 |
|Cat3 | 3 | 5 | 4 | 12 |
|Cat4 | 3 | 1 | 2 | 6 |
+------------------------------------------------------------+
|Total per loc | 9 | 9 | 10 | 28 |
+------------------------------------------------------------+