The SQL Server SELECT statement in 60 seconds - the GROUP BY Clause #shorts

preview_player
Показать описание
In 60 seconds we'll explore the GROUP BY clause in SQL.
My SQL Server Udemy courses are:
----
In this video, I'll walk you through the basics of the SQL Server SELECT statement, including the GROUP BY Clause. I'll give you a quick overview of this important clause, and then demonstrate how to use it in a simple example.

If you're new to SQL Server, or if you're just looking for a refresher on how to use the SELECT statement, this video is for you! I'll take you through the basics of the SELECT statement, including the GROUP BY Clause. By the end of this video, you'll have a clear understanding of how this clause can help you to dataanalyse your data in a concise and organized way.

The GROUP BY clause is the fourth clause in the SELECT statement in SQL, after the SELECT, FROM and WHERE. The WHERE clause is optional.

SELECT schema_id, type
-- WHERE

It allows you to summarise data which has been retrieved from the FROM clause, and filtered in the WHERE clause.
It is most often used when you use an aggregation in the SELECT clause, such as SUM, COUNT, AVG, MIN and MAX. The aggregation should have an alias.
When an aggregation is used, any non-aggregated columns shown in the SELECT clause must be included in the GROUP BY clause. Multiple columns should be separated by commas.

SELECT schema_id, type, COUNT(*) AS NumberOfObjects
GROUP BY schema_id, type

The result is all of the possible values of the columns shown in the GROUP BY clause without any duplicates, together with all of the aggregations shown in the SELECT clause.
A GROUP BY clause does not guarantee the order of the results – you will need to use a ORDER BY Clause for that. Often it will resemble the GROUP BY clause.

SELECT schema_id, type, COUNT(*) AS NumberOfObjects
GROUP BY schema_id, type
ORDER BY schema_id, type

----
Links to my website are:
Рекомендации по теме