← All SQL interview questions
Duplicate support tickets from the same customer
MediumGROUP BYZomatoTarget
Support wants to merge duplicate tickets. A duplicate is the same customer raising the same issue category more than once on the same day.
From support_tickets, return customer_code, issue_category, raised_on and ticket_count for every such duplicated combination.
Sample data
Table: support_tickets
16 row(s) · showing first 8
| ticket_idINT | customer_codeTEXT | issue_categoryTEXT | raised_onDATE |
|---|---|---|---|
| 1 | CU-11 | Refund Delay | 2026-02-10 |
| 2 | CU-11 | Refund Delay | 2026-02-10 |
| 3 | CU-11 | Refund Delay | 2026-02-12 |
| 4 | CU-12 | Wrong Item | 2026-02-10 |
| 5 | CU-13 | App Crash | 2026-02-11 |
| 6 | CU-13 | App Crash | 2026-02-11 |
| 7 | CU-13 | App Crash | 2026-02-11 |
| 8 | CU-14 | Late Delivery | 2026-02-11 |
support_tickets
- ticket_idINT
- customer_codeTEXT
- issue_categoryTEXT
- raised_onDATE
- Step 1: Translate the business definition of “duplicate” into a grouping key: customer + issue category + date. All three columns go into the `GROUP BY`.
- Step 2: `COUNT(*)` tells you how many tickets landed in each of those buckets.
- Step 3: Keep only buckets with more than one ticket using `HAVING COUNT(*) > 1` — the filter applies to the aggregate, so it cannot live in `WHERE`.
- Step 4: Project the three key columns plus the count so support knows how many tickets to merge.
SELECT customer_code, issue_category, raised_on, COUNT(*) AS ticket_count
FROM support_tickets
GROUP BY customer_code, issue_category, raised_on
HAVING COUNT(*) > 1;More GROUP BY questions
Practising alone only goes so far — our live cohorts pair SQL depth with dashboards, agentic analytics projects and mock interviews.
Explore the program