Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Grouping by multiple columns | Grouping
SQL Basics
course content

Зміст курсу

SQL Basics

SQL Basics

1. Selecting
2. Filtering
3. Aggregating
4. Sorting
5. Grouping
6. Practicing

Grouping by multiple columns

Can we group observations based on multiple columns? For example, we can group all cars by year and engine size and find the most expensive within these.

To group by multiple columns use the same approach as for sorting by multiple columns: just put it within GROUP BY statement separated with a comma. The query for the example above will look like this:

123
SELECT year, enginesize, AVG(price) FROM audi_cars GROUP BY year, enginesize
copy

Завдання

From the audi_cars table calculate the maximum, average, and minimum price for each model manufactured in different years.

Завдання

From the audi_cars table calculate the maximum, average, and minimum price for each model manufactured in different years.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 5. Розділ 3
toggle bottom row

Grouping by multiple columns

Can we group observations based on multiple columns? For example, we can group all cars by year and engine size and find the most expensive within these.

To group by multiple columns use the same approach as for sorting by multiple columns: just put it within GROUP BY statement separated with a comma. The query for the example above will look like this:

123
SELECT year, enginesize, AVG(price) FROM audi_cars GROUP BY year, enginesize
copy

Завдання

From the audi_cars table calculate the maximum, average, and minimum price for each model manufactured in different years.

Завдання

From the audi_cars table calculate the maximum, average, and minimum price for each model manufactured in different years.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 5. Розділ 3
toggle bottom row

Grouping by multiple columns

Can we group observations based on multiple columns? For example, we can group all cars by year and engine size and find the most expensive within these.

To group by multiple columns use the same approach as for sorting by multiple columns: just put it within GROUP BY statement separated with a comma. The query for the example above will look like this:

123
SELECT year, enginesize, AVG(price) FROM audi_cars GROUP BY year, enginesize
copy

Завдання

From the audi_cars table calculate the maximum, average, and minimum price for each model manufactured in different years.

Завдання

From the audi_cars table calculate the maximum, average, and minimum price for each model manufactured in different years.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Can we group observations based on multiple columns? For example, we can group all cars by year and engine size and find the most expensive within these.

To group by multiple columns use the same approach as for sorting by multiple columns: just put it within GROUP BY statement separated with a comma. The query for the example above will look like this:

123
SELECT year, enginesize, AVG(price) FROM audi_cars GROUP BY year, enginesize
copy

Завдання

From the audi_cars table calculate the maximum, average, and minimum price for each model manufactured in different years.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 5. Розділ 3
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt