0Pricing
SQL Academy · Lesson

GROUP BY Single and Multiple Columns

Group rows by one or more columns to produce subtotals and category breakdowns, and read GROUP BY query plans.

What GROUP BY Does

GROUP BY partitions rows into groups by one or more column values, then applies aggregates per group.

Single-Column Group

Total orders per user:

SELECT user_id, COUNT(*) AS order_count, SUM(total) AS revenue
FROM orders
GROUP BY user_id
ORDER BY revenue DESC;

All lessons in this course

  1. COUNT, SUM, AVG, MIN, MAX
  2. GROUP BY Single and Multiple Columns
  3. HAVING vs WHERE
  4. Common Pitfalls: NULLs in Aggregates
← Back to SQL Academy