message_events has one row per chat message event (user_id, event_type, event_id) where event_type is 'sent', 'opened' or another value to ignore. For every user who appears in the table, count the messages sent and the messages opened (0 when none). Output columns: user_id, sent_count, opened_count. Order by user_id ascending.
| Column | Type |
|---|---|
| user_id | INTEGER |
| event_type | TEXT |
| event_id | INTEGER |
| user_id | event_type | event_id |
|---|---|---|
| 1 | sent | 1 |
| 1 | opened | 2 |
| 1 | sent | 3 |
| 2 | sent | 4 |
| 2 | sent | 5 |
| 2 | opened | 6 |
| user_id | sent_count | opened_count |
|---|---|---|
| 1 | 2 | 1 |
| 2 | 2 | 1 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Second Distinct Compensation Level · Three-Day Activity Trend ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.