Data aggregation
Find out the number of unique episodes within every season of every series.
Note
We assume that you already created tables in step Creating a table and populated them with data in step Adding data to a table.
1. SELECT
2. series_id,
3. season_id,
4. COUNT(*) AS cnt -- Aggregation function COUNT returns the number of rows
5. -- output by the query.
6. -- Asterisk (*) specifies that COUNT
7. -- counts the total number of rows in the table.
8. -- COUNT(*) returns the number of rows in
9. -- the specified table, preserving the duplicate rows.
10. -- It counts each row separately.
11. -- The result includes rows that contain null values.
12. FROM episodes
14. GROUP BY
15. series_id, -- The query result will follow the listed order of columns.
16. season_id -- Multiple columns are separated by a comma.
17. -- Other columns can be listed after a SELECT only if
18. -- they are passed to an aggregate function.
19. ORDER BY
20. series_id,
21. season_id
22. ;
24. COMMIT;

