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.
SELECT
series_id,
season_id,
COUNT(*) AS cnt -- Aggregation function COUNT returns the number of rows
-- output by the query.
-- Asterisk (*) specifies that COUNT
-- counts the total number of rows in the table.
-- COUNT(*) returns the number of rows in
-- the specified table, preserving the duplicate rows.
-- It counts each row separately.
-- The result includes rows that contain null values.
FROM episodes
GROUP BY
series_id, -- The query result will follow the listed order of columns.
season_id -- Multiple columns are separated by a comma.
-- Other columns can be listed after a SELECT only if
-- they are passed to an aggregate function.
ORDER BY
series_id,
season_id
;
COMMIT;