NewProject Coding is here — build features and fix bugs in real codebases with an AI assistantSee what's new

Table: messages

+-------------+----------+
| Column Name | Type     |
+-------------+----------+
| message_id  | integer  |
| sender_id   | integer  |
| receiver_id | integer  |
| content     | varchar  |
| sent_date   | date     |
+-------------+----------+

message_id is the primary key. Each row represents a message sent from one user to another.

Write a solution to find the top 2 senders by number of messages sent in August 2022. Return sender_id and message_count, ordered by message_count descending. In case of a tie in message_count, order by sender_id in ascending order.

The result format is shown below.

Example

Input:

messages table:
+------------+-----------+-------------+-------------------------+------------+
| message_id | sender_id | receiver_id | content                 | sent_date  |
+------------+-----------+-------------+-------------------------+------------+
| 901        | 3601      | 4500        | You up?                 | 2022-08-03 |
| 902        | 4500      | 3601        | Only if you're buying   | 2022-08-03 |
| 743        | 3601      | 8752        | Let's take this offline | 2022-06-14 |
| 922        | 3601      | 4500        | Get on the call         | 2022-08-10 |
+------------+-----------+-------------+-------------------------+------------+

Output:

+-----------+---------------+
| sender_id | message_count |
+-----------+---------------+
| 3601      | 2             |
| 4500      | 1             |
+-----------+---------------+

Explanation:
Message 743 was sent in June 2022, not August, so it is excluded. In August 2022, sender 3601 sent 2 messages (IDs 901 and 922) and sender 4500 sent 1 message (ID 902).


Accepted
9/23
Acceptance Rate39.1%
Test Cases
Input
-
Output
-
Expected
-