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

Course Content

SQL Basics

SQL Basics

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

bookHAVING some conditions

What if we want to filter grouped observations based on some condition? For example, we want to extract only those models available with Hybrid fuel types.

You can do it by grouping firstly by model, and then by fuel type filtered by condition on fueltype.

1234
SELECT model FROM audi_cars GROUP BY model, fueltype HAVING fueltype = 'Hybrid'
copy

Please note, that you can use all the operators learned in the second section within HAVING statement.

Task

From the audi_cars table extract all the models available with Automatic transmission.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 5
toggle bottom row

bookHAVING some conditions

What if we want to filter grouped observations based on some condition? For example, we want to extract only those models available with Hybrid fuel types.

You can do it by grouping firstly by model, and then by fuel type filtered by condition on fueltype.

1234
SELECT model FROM audi_cars GROUP BY model, fueltype HAVING fueltype = 'Hybrid'
copy

Please note, that you can use all the operators learned in the second section within HAVING statement.

Task

From the audi_cars table extract all the models available with Automatic transmission.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 5
toggle bottom row

bookHAVING some conditions

What if we want to filter grouped observations based on some condition? For example, we want to extract only those models available with Hybrid fuel types.

You can do it by grouping firstly by model, and then by fuel type filtered by condition on fueltype.

1234
SELECT model FROM audi_cars GROUP BY model, fueltype HAVING fueltype = 'Hybrid'
copy

Please note, that you can use all the operators learned in the second section within HAVING statement.

Task

From the audi_cars table extract all the models available with Automatic transmission.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

What if we want to filter grouped observations based on some condition? For example, we want to extract only those models available with Hybrid fuel types.

You can do it by grouping firstly by model, and then by fuel type filtered by condition on fueltype.

1234
SELECT model FROM audi_cars GROUP BY model, fueltype HAVING fueltype = 'Hybrid'
copy

Please note, that you can use all the operators learned in the second section within HAVING statement.

Task

From the audi_cars table extract all the models available with Automatic transmission.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 5. Chapter 5
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt