messages(message_id, user_id, sent_at)
For the calendar week beginning 2026-09-07 (seven days, up to and including 2026-09-13), build a histogram of how busy users were: how many users sent exactly 1 message, how many sent exactly 2, and so on.
Users who sent nothing that week do not appear. Return messages_sent and
user_count, ordered by messages_sent.
Two levels of grouping: count per user first, then count the users at each count.
Tables
messages
message_id user_id sent_at
---------- ------- -------------------
1 10 2026-09-07 09:00:00
2 10 2026-09-09 10:00:00
3 11 2026-09-08 11:00:00
4 12 2026-09-10 12:00:00
5 12 2026-09-11 13:00:00
6 12 2026-09-13 23:59:59
7 13 2026-09-06 23:59:59
8 14 2026-09-14 00:00:00
Expected result
messages_sent user_count
------------- ----------
1 1
2 1
3 1
Sign in to write and run your own code.
SELECT query