I got a field "type" which is either "member" or "casual". I got another categorical field called "duration_type".
And I want to calculate the percentage of each categories in the duration_type, separately for members and casual users.
So I run two separate scripts where their only difference is the WHERE type = "member" becomes WHERE type = "casual" .
SELECT
type,
duration_type,
CONCAT(ROUND((COUNT(*)/ (SELECT COUNT(*) FROM temp WHERE type ="member")*100 ),2),"%") AS per
FROM temp
WHERE type = "member"
GROUP BY duration_type;
SELECT
type,
duration_type,
CONCAT(ROUND((COUNT(*)/ (SELECT COUNT(*) FROM temp WHERE type ="casual")*100 ),2),"%") AS per
FROM temp
WHERE type = "casual"
GROUP BY duration_type;
Is there a more compact way to do this in only one command? Simply using GROUP BY type, duration_type is not correct.