FLOOR(download_count/100) * 100 as download_range_start, FLOOR(download_count/100) * 100 + 99 as download_range_end, COUNT(*) as user_count FROM (SELECT user_id, COUNT(*) as download_count FROM download_history GROUP BY user_id) user_downloads GROUP BY FLOOR(download_count/100) ORDER BY download_range_start;