So I have the query below which gets the count of each route_grade for a person.
Code:
SELECT
COUNT(*) AS 'count',
r.`route_grade`
FROM `mc_routes` r, `mc_routeclimbs` c, `mc_areas` a, `mc_countries` co
WHERE c.`route_id` = r.`route_id`
AND r.`area_id` = a.`area_id`
AND a.`country_id` = co.`country_id`
AND c.`user_id` = :user_id
GROUP BY r.`route_grade`
ORDER BY r.`route_grade` DESC
The route_grade is an enum field in the mc_routes table:
Code:
`route_grade` enum('3','4','5a','5a+','5b','5b+','5c','5c+','6a','6a+','6b','6b+','6c','6c+','7a','7a+','7b','7b+','7c','7c+','8a','8a+','8b','8b+','8c','8c+','9a','9a+','9b','9b+') NOT NULL,
So for a given person the results might look like:
So he climbed 12 routes graded 5b, 8 routes graded 6c and 3 routes graded 7a. However, what I want is to also have results for the grades with no results. Meaning:
Code:
3 0
4 0
5a 0
.. etc
5b 12
5c 0
.. etc
I could do this with some PHP logic, but I'm sure there's a way to do it in the mysql query. Any ideas?