You are a Data Analyst at a SaaS company that provides a customer support platform. The operations manager wants a quick summary of the current state of the support queue to understand how many tickets exist in each status category. This helps the team prioritize resources and identify potential bottlenecks in the support workflow. The database has a single table called support_tickets with the following key columns: ticket_id (unique identifier for each ticket), customer_id (the customer who raised the ticket), subject (brief description of the issue), status (current state of the ticket — one of 'open' , 'in_progress' , 'resolved' , or 'closed' ), and created_at (timestamp when the ticket was created). Return each unique status value and the total number of tickets in that status as ticket_count . Include all statuses that exist in the table — do not hard-code or filter any specific status. Order the results by ticket_count in descending order so the most common status appears first. Hint: This is a straightforward GROUP BY aggregation problem — group by the status column and use COUNT(*) to tally the rows in each group. A common pitfall is using COUNT(column_name) instead of COUNT(*) — if the column you count contains any NULL values, those rows will be silently excluded from the count. Since you want to count all tickets regardless of column values, COUNT(*) is the safer and more correct choice here.
Table Setup (SQL Schema)
CREATE TABLE support_tickets (
ticket_id SERIAL PRIMARY KEY,
customer_id INT NOT NULL,
subject VARCHAR(150) NOT NULL,
status VARCHAR(20) NOT NULL,
created_at TIMESTAMP NOT NULL
);
INSERT INTO support_tickets (customer_id, subject, status, created_at) VALUES
(101, 'Cannot login to account', 'open', '2024-06-01 09:00:00'),
(102, 'Billing charge incorrect', 'open', '2024-06-01 10:30:00'),
(103, 'Feature request: dark mode', 'closed', '2024-06-02 08:15:00'),
(104, 'App crashes on startup', 'in_progress', '2024-06-02 11:00:00'),
(105, 'Cannot export CSV', 'open', '2024-06-03 09:45:00'),
(106, 'Password reset email not received', 'resolved', '2024-06-03 14:00:00'),
(107, 'Slow dashboard loading', 'in_progress', '2024-06-04 10:00:00'),
(108, 'Integration with Slack broken', 'open', '2024-06-04 13:30:00'),
(109, 'Invoice PDF not generating', 'resolved', '2024-06-05 09:00:00'),
(110, 'Account locked after failed logins', 'open', '2024-06-05 11:15:00'),
(111, 'Data not syncing in real time', 'in_progress', '2024-06-06 08:30:00'),
(112, 'Notification settings not saving', 'closed', '2024-06-06 10:00:00'),
(113, 'API rate limit too low', 'closed', '2024-06-07 09:00:00'),
(114, 'Wrong timezone displayed', 'resolved', '2024-06-07 12:00:00'),
(115, 'Mobile app login loop', 'open', '2024-06-08 08:00:00');