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
  13. GROUP BY
  14. series_id, -- The query result will follow the listed order of columns.
  15. season_id -- Multiple columns are separated by a comma.
  16. -- Other columns can be listed after a SELECT only if
  17. -- they are passed to an aggregate function.
  18. ORDER BY
  19. series_id,
  20. season_id
  21. ;
  22. COMMIT;

Data aggregation - 图1