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

Опубликовано: 22 Июнь 2023
на канале: SQL Server 101
1,107
49

In 60 seconds we'll explore the GROUP BY clause in SQL.
My SQL Server Udemy courses are:
70-461, 70-761 Querying Microsoft SQL Server with T-SQL: https://rebrand.ly/querying-microsoft...
98-364: Database Fundamentals (Microsoft SQL Server): https://rebrand.ly/database-fundamentals
70-462 SQL Server Database Administration (DBA): https://rebrand.ly/sql-server-dba
Microsoft SQL Server Reporting Services (SSRS): https://rebrand.ly/sql-server-ssrs
SQL Server Integration Services (SSIS): https://rebrand.ly/sql-server-ssis
SQL Server Analysis Services (SSAS): https://rebrand.ly/sql-server-ssas-mdx
Microsoft Power Pivot (Excel) and SSAS (Tabular DAX model): https://rebrand.ly/microsoft-powerpiv...
----
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
FROM sys.objects
-- 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
FROM sys.objects
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
FROM sys.objects
GROUP BY schema_id, type
ORDER BY schema_id, type

I’m Phillip Burton from IDoData.com, where we have our courses on SQL and more. Please see our other videos and Keep learning!

----
Links to my website are:
70-461, 70-761 Querying Microsoft SQL Server with T-SQL: http://idodata.com/querying-microsoft...
98-364: Database Fundamentals (Microsoft SQL Server): http://idodata.com/database-fundament...
SQL Server Essential in an Hour: http://idodata.com/sql-server-essenti...
70-462 SQL Server Database Administration (DBA): http://idodata.com/sql-server-databas...
DP-300: Administering Relational Databases: http://idodata.com/dp-300-administeri...
Microsoft SQL Server Reporting Services (SSRS): http://idodata.com/microsoft-sql-serv...
SQL Server Integration Services (SSIS): http://idodata.com/sql-server-integra...
SQL Server Analysis Services (SSAS): http://idodata.com/sql-server-ssas-mu...
Microsoft Power Pivot (Excel) and SSAS (Tabular DAX model): https://rebrand.ly/microsoft-powerpiv...
1Z0-071 Oracle SQL Developer – certified associate: http://idodata.com/iz0-071-oracle-sql...
SQL for Microsoft Access: http://idodata.com/sql-for-microsoft-...
DP-900: Microsoft Azure Data Fundamentals: http://idodata.com/dp-900-microsoft-a...


Смотрите видео The SQL Server SELECT statement in 60 seconds - the GROUP BY Clause онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал SQL Server 101 22 Июнь 2023. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 1,107 раз и оно понравилось 49 посетителям.