Open Tickets by Priority
The support team stores tickets in tickets. status is one of open, pending or closed.
For each priority, count the tickets whose status is open. Priorities with no open tickets should not appear.
Return columns priority, open_tickets. Row order does not matter.
Schema
CREATE TABLE tickets ( ticket_id INTEGER PRIMARY KEY, priority TEXT NOT NULL, status TEXT NOT NULL, created_at TEXT NOT NULL );
Sample data
tickets
| ticket_id | priority | status | created_at |
|---|---|---|---|
| 1 | high | open | 2026-04-01 09:00:00 |
| 2 | low | open | 2026-04-01 10:15:00 |
| 3 | high | closed | 2026-04-01 11:30:00 |
| 4 | medium | open | 2026-04-02 08:45:00 |
| 5 | high | open | 2026-04-02 13:05:00 |
| 6 | low | pending | 2026-04-03 16:20:00 |
| 7 | medium | open | 2026-04-03 17:00:00 |
| 8 | urgent | closed | 2026-04-04 07:10:00 |
Hint 1
Filter to open tickets with WHERE before grouping.
Hint 2
GROUP BY priority and COUNT(*) the rows in each group.
Good practice for: Data Analyst, Business Analyst, Product Manager
SQL (SQLite)
Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.