Question: What is the percentage distribution of years of experience among all respondents grouped into buckets of 5 years?
SQL:
SELECT CEIL(WorkExp / 5) * 5 AS bucket_start, CEIL(WorkExp / 5) * 5 + 4 AS bucket_end, COUNT(WorkExp) * 100.0 / (SELECT COUNT(WorkExp) FROM Responses) AS count_in_bucket FROM Responses WHERE NOT WorkExp IS NULL GROUP BY CEIL(WorkExp / 5)
SELECT CASE WHEN WorkExp BETWEEN 0 AND 5 THEN '0-5' WHEN WorkExp BETWEEN 6 AND 10 THEN '6-10' WHEN WorkExp BETWEEN 11 AND 15 THEN '11-15' WHEN WorkExp BETWEEN 16 AND 20 THEN '16-20' WHEN WorkExp BETWEEN 21 AND 25 THEN '21-25' WHEN WorkExp BETWEEN 26 AND 30 THEN '26-30' WHEN WorkExp BETWEEN 31 AND 35 THEN '31-35' WHEN WorkExp BETWEEN 36 AND 40 THEN '36-40' WHEN WorkExp BETWEEN 41 AND 45 THEN '41-45' WHEN WorkExp BETWEEN 46 AND 50 THEN '46-50' ELSE '50+' END AS "Experience_Bucket", COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Responses WHERE NOT WorkExp IS NULL) AS "Percentage" FROM Responses WHERE NOT WorkExp IS NULL GROUP BY Experience_Bucket ORDER BY MIN(WorkExp)