---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.4
alternate:
  - https://ydb.tech/docs/en/dev/yql-tutorial/basic_aggregation.md
  - https://ydb.tech/docs/ru/dev/yql-tutorial/basic_aggregation.md
sourcePath: en/core/dev/yql-tutorial/basic_aggregation.md
---
> **Documentation Index:** Fetch the complete configuration index at https://ydb.tech/docs/en/llms.txt

# Data aggregation

Find out the number of unique episodes within every season of every series.

<!-- source: en/dev/yql-tutorial/_includes/yql_tutorial_prerequisites.md -->
{% note info %}

We assume that you already created tables in step [Creating a table](https://ydb.tech/docs/en/dev/yql-tutorial/create_demo_tables.md) and populated them with data in step [Adding data to a table](https://ydb.tech/docs/en/dev/yql-tutorial/fill_tables_with_data.md).

{% endnote %}
<!-- endsource: en/dev/yql-tutorial/_includes/yql_tutorial_prerequisites.md -->

```yql
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;
```

