Select Grouped and Aggregated Data with SQL

InstructorTyler Clark

Share this video with your friends

Send Tweet

Another powerful SQL skill is understanding how to group rows together by column values. Once the data is grouped together, it can be difficult to understand how to actually work with the groupings. In this lesson, we will use the group by clause, as well as the count, sum, avg, min, and max aggregate functions.

Counts with create date and first name example:

SELECT u.total, u.create_date, first_name 
FROM Users us 
INNER JOIN (SELECT count(create_date) AS total, create_date 
   FROM Users
   GROUP BY create_date) u ON u.create_date = us.create_date;

Min create date with first name example:

SELECT create_date, first_name 
FROM Users 
WHERE create_date = (select min(create_date) FROM Users);

Aggregate functions:

https://www.postgresql.org/docs/9.5/functions-aggregate.html https://dev.mysql.com/doc/refman/8.0/en/group-by-functions.html https://docs.microsoft.com/en-us/sql/t-sql/functions/aggregate-functions-transact-sql https://docs.oracle.com/database/121/SQLRF/functions003.htm