i have the following SQL query and i was wondering if i can make the SUM() part of it dynamic so that i don't have to put category_id (2 and 3)
SELECT
a.project_id,
COUNT(a.id) AS Total,
SUM(CASE WHEN a.category_id = 2 AND a.`status` < 80 THEN 1 ELSE 0 END) AS 'Bugs En cours',
SUM(CASE WHEN a.category_id = 2 AND a.`status` >= 80 THEN 1 ELSE 0 END) AS 'Bugs Resolu',
SUM(CASE WHEN a.category_id = 3 AND a.`status` < 80 THEN 1 ELSE 0 END) AS 'Ameliorations En cours',
SUM(CASE WHEN a.category_id = 3 AND a.`status` >= 80 THEN 1 ELSE 0 END) AS 'Ameliorations Resolu'
FROM bugs a
GROUP BY a.project_id
HAVING COUNT(a.id) > 0
The goal is to list the project id and the count of different Anomalies depending on the category_id and on the status ('En cours' OR 'Resolu')
The issue in this query is that if we added another category, i will have to manually edit this query which is not ideal.