Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
More aggregate statistics! | Grouping
SQL Basics
course content

Зміст курсу

SQL Basics

SQL Basics

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

bookMore aggregate statistics!

Can we calculate more than one aggregate statistic while grouping? Surely we can!

For example, from the audi_cars table, we can calculate the maximum price and tax for each year.

123
SELECT AVG(price) AS "avg_price", AVG(tax) AS "avg_tax", year FROM audi_cars GROUP BY year
copy

Please note, while grouping you can put non-aggregated function within SELECT statement only if it figures within GROUP BY, otherwise - it has to be aggregated.

Also note, that in the example above without aliases (AS) there will be two columns with identical names, which is unacceptable in SQL.

Another note: you can use aggregate functions for ordering after GROUP BY statement. It will filter based on calculations within groups.

Завдання

From the audi_cars table find out the minimum and the maximum prices for each model. Sort in descending order by minimum price.

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

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

bookMore aggregate statistics!

Can we calculate more than one aggregate statistic while grouping? Surely we can!

For example, from the audi_cars table, we can calculate the maximum price and tax for each year.

123
SELECT AVG(price) AS "avg_price", AVG(tax) AS "avg_tax", year FROM audi_cars GROUP BY year
copy

Please note, while grouping you can put non-aggregated function within SELECT statement only if it figures within GROUP BY, otherwise - it has to be aggregated.

Also note, that in the example above without aliases (AS) there will be two columns with identical names, which is unacceptable in SQL.

Another note: you can use aggregate functions for ordering after GROUP BY statement. It will filter based on calculations within groups.

Завдання

From the audi_cars table find out the minimum and the maximum prices for each model. Sort in descending order by minimum price.

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

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

bookMore aggregate statistics!

Can we calculate more than one aggregate statistic while grouping? Surely we can!

For example, from the audi_cars table, we can calculate the maximum price and tax for each year.

123
SELECT AVG(price) AS "avg_price", AVG(tax) AS "avg_tax", year FROM audi_cars GROUP BY year
copy

Please note, while grouping you can put non-aggregated function within SELECT statement only if it figures within GROUP BY, otherwise - it has to be aggregated.

Also note, that in the example above without aliases (AS) there will be two columns with identical names, which is unacceptable in SQL.

Another note: you can use aggregate functions for ordering after GROUP BY statement. It will filter based on calculations within groups.

Завдання

From the audi_cars table find out the minimum and the maximum prices for each model. Sort in descending order by minimum price.

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Can we calculate more than one aggregate statistic while grouping? Surely we can!

For example, from the audi_cars table, we can calculate the maximum price and tax for each year.

123
SELECT AVG(price) AS "avg_price", AVG(tax) AS "avg_tax", year FROM audi_cars GROUP BY year
copy

Please note, while grouping you can put non-aggregated function within SELECT statement only if it figures within GROUP BY, otherwise - it has to be aggregated.

Also note, that in the example above without aliases (AS) there will be two columns with identical names, which is unacceptable in SQL.

Another note: you can use aggregate functions for ordering after GROUP BY statement. It will filter based on calculations within groups.

Завдання

From the audi_cars table find out the minimum and the maximum prices for each model. Sort in descending order by minimum price.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 5. Розділ 2
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
some-alt