GROUP BY can use two columns so each category and status pair gets its own count.

highlighted = computed this step

Input table

Start with sales rows that have both category and status labels.

Sales with status\text{Sales with status}
Salesorder_idcategorystatuso1bookpaido2bookpaido3bookrefundedo4penpaido5penpending

Group query

Group by category and status together, then count every row in each pair.

GROUP BY category, status\text{GROUP BY category, status}
GROUP BY category and status countgroup_byarity 3 rows 4Salesarity 3 rows 5

Grouped output

The book rows split into paid and refunded buckets instead of one book bucket.

counts by two keys\text{counts by two keys}
Grouped outputcategorystatusorder_countbookpaid2bookrefunded1penpaid1penpending1