Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
SQL Group By | Filtering Statements
SQL Tutorial for Beginners
course content

Зміст курсу

SQL Tutorial for Beginners

SQL Tutorial for Beginners

1. Database & Introduction to Syntax
2. SQL Aggregate Functions
3. Filtering Statements

SQL Group By

GROUP BY is an operator that puts rows with the same values of the field in groups. It creates one row for each group, so it makes sense to use some aggregate function in SELECT. For example, let's group our songs by singers, and find a number of songs for each singer:

123
SELECT COUNT(Id), singer FROM songs GROUP BY singer
copy

This query will return a list of singers, as well as, for each of them, the number of songs. Each singer represents a unit or group, and COUNT() aggregate function is applied for records in the group. You can use GROUP BY with ORDER BY, and also group by multiple columns. Here is a syntax of query:

123456
-- do not run this query SELECT col1, col2, ... FROM table WHERE condition GROUP BY col1, col2, ... ORDER BY col1, col2, ...;
copy

Завдання

For each singer, create groups with info about singer and price of the most expensive song. Order these groups by singer.

Завдання

For each singer, create groups with info about singer and price of the most expensive song. Order these groups by singer.

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

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

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

SQL Group By

GROUP BY is an operator that puts rows with the same values of the field in groups. It creates one row for each group, so it makes sense to use some aggregate function in SELECT. For example, let's group our songs by singers, and find a number of songs for each singer:

123
SELECT COUNT(Id), singer FROM songs GROUP BY singer
copy

This query will return a list of singers, as well as, for each of them, the number of songs. Each singer represents a unit or group, and COUNT() aggregate function is applied for records in the group. You can use GROUP BY with ORDER BY, and also group by multiple columns. Here is a syntax of query:

123456
-- do not run this query SELECT col1, col2, ... FROM table WHERE condition GROUP BY col1, col2, ... ORDER BY col1, col2, ...;
copy

Завдання

For each singer, create groups with info about singer and price of the most expensive song. Order these groups by singer.

Завдання

For each singer, create groups with info about singer and price of the most expensive song. Order these groups by singer.

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

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

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

SQL Group By

GROUP BY is an operator that puts rows with the same values of the field in groups. It creates one row for each group, so it makes sense to use some aggregate function in SELECT. For example, let's group our songs by singers, and find a number of songs for each singer:

123
SELECT COUNT(Id), singer FROM songs GROUP BY singer
copy

This query will return a list of singers, as well as, for each of them, the number of songs. Each singer represents a unit or group, and COUNT() aggregate function is applied for records in the group. You can use GROUP BY with ORDER BY, and also group by multiple columns. Here is a syntax of query:

123456
-- do not run this query SELECT col1, col2, ... FROM table WHERE condition GROUP BY col1, col2, ... ORDER BY col1, col2, ...;
copy

Завдання

For each singer, create groups with info about singer and price of the most expensive song. Order these groups by singer.

Завдання

For each singer, create groups with info about singer and price of the most expensive song. Order these groups by singer.

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

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

GROUP BY is an operator that puts rows with the same values of the field in groups. It creates one row for each group, so it makes sense to use some aggregate function in SELECT. For example, let's group our songs by singers, and find a number of songs for each singer:

123
SELECT COUNT(Id), singer FROM songs GROUP BY singer
copy

This query will return a list of singers, as well as, for each of them, the number of songs. Each singer represents a unit or group, and COUNT() aggregate function is applied for records in the group. You can use GROUP BY with ORDER BY, and also group by multiple columns. Here is a syntax of query:

123456
-- do not run this query SELECT col1, col2, ... FROM table WHERE condition GROUP BY col1, col2, ... ORDER BY col1, col2, ...;
copy

Завдання

For each singer, create groups with info about singer and price of the most expensive song. Order these groups by singer.

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