Lesson 22 / 37 · Grouping

An aggregate without GROUP BY makes one group

With aggregates but no GROUP BY, the whole input is one group and the result is one row. dequery still shows the GROUP BY step: a single band with every row in it. That is also why SELECT status, count(*) FROM orders is an error: status has no single value for the group.

The query

SELECT count(*) AS orders, sum(amount) AS revenue, avg(amount) AS average
FROM orders
WHERE status = 'paid'

Try adding GROUP BY customer_id: the single group splits into 8, one per customer.

Next: count(*), count(col) and count(DISTINCT col) count different things · All lessons