Getting percentage of “Count(*)” to the number of all items in “GROUP BY”

SELECT Category, COUNT(*) AS Total , (COUNT(*) / (SELECT COUNT(*) FROM Item WHERE Department="Popular")) * 100 AS 'Percentage to all items', 
FROM Item
WHERE Department="Popular"
GROUP BY Category;

I’m not sure of the MySql syntax, but you can use a sub-query as shown.

Leave a Comment