Example 1
Count tickets by team and status
Each unique pair of team and status becomes its own result row. Billing has one open ticket and two closed tickets; Support has two open tickets and one closed ticket.
Source table data Rows loaded before the example query runs.
Setup
CREATE TABLE tickets (id INT, team VARCHAR(20), status VARCHAR(20));
INSERT INTO
tickets (id, team, status)
VALUES
(1, 'Support', 'open'),
(2, 'Support', 'open'),
(3, 'Support', 'closed'),
(4, 'Billing', 'open'),
(5, 'Billing', 'closed'),
(6, 'Billing', 'closed');Validated query Shared across supported engines.
SQL
SELECT
team,
status,
COUNT(*) AS total_tickets
FROM
tickets
GROUP BY
team,
status
ORDER BY
team,
status;Expected result Returned rows for the shared example.
| team | status | total_tickets |
|---|---|---|
| Billing | closed | 2 |
| Billing | open | 1 |
| Support | closed | 1 |
| Support | open | 2 |
All engines group by the same `(team, status)` combinations and return the same counts here.