-- Create Bins with upper and lower bound
WITH bins AS (
SELECT generate_series(2200, 3050, 50) AS lower,
generate_series(2250, 3100, 50) AS upper),
-- Take the counts from desired table
temp_table AS (
SELECT question_count
FROM table_name)
-- Select columns for result
SELECT lower, upper, count(question_count)
FROM bins -- Created above
-- Join to temp_table (created above),
-- keeping all rows from the bins table in the join
LEFT JOIN temp_table
-- Compare question_count to lower and upper
ON question_count >= lower
AND question_count < upper
-- Group by lower and upper to count values in each bin
GROUP BY lower, upper
-- Order by lower to put bins in order
ORDER BY lower;