Counting with conditions
Put a CASE inside SUM to count only some rows, side by side in one result:
SELECT channel,
COUNT(*) AS orders,
SUM(CASE WHEN status = 'Returned' THEN 1 ELSE 0 END) AS returned
FROM orders
GROUP BY channelFor each order the CASE gives 1 if it was returned and 0 if not, so the SUM counts the
returns. This is how you build a summary table with several measures across the top, like a
pivot table.