Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre What is grouping? | Grouping
SQL Basics

book
What is grouping?

Grouping - is arranging observations into sub-groups based on unique values in some column. For example, we can group our audi_cars table by transmission column (contains 3 unique values). There will be observations within each subgroup. So, what's the point of grouping?

In SQL grouping is often used in pair with some aggregate function within SELECT. For example, we can calculate the average price for each transmission type.

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

This will return all the transmissions types with average prices within each group.

Tâche

Swipe to start coding

From the audi_cars table calculate the average price of each model. Round price to two decimals.

Solution

SELECT model, ROUND(AVG(price),2)
FROM audi_cars
GROUP BY model

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 5. Chapitre 1

toggle bottom row
Query ResultQuery Result
No query executed yet...
some-alt