GROUP BY calculates one summary row for each group.
GROUP BY calculates one summary row for each group. Read the query line by line and identify the input table, the transformation, and the shape of the result before running it.
SELECT customer_id, SUM(amount) AS total_revenue FROM orders GROUP BY customer_id ORDER BY total_revenue DESC;
Before running the example, predict the output columns and whether the query returns one row, many rows, or possibly no rows.
In your own words, explain the main SQL feature in today’s lesson and why it answers the question.
Recall prompt: Group by customer_id and sum amount. Close this page section mentally and explain the query from memory before proceeding.
Calculate total order value for each customer, highest first.
Group by customer_id and sum amount.