Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

# Select Grouped and Aggregated Data with SQL

PostgreSQL

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:

`.css-1nz60a6{text-align:left;padding:30px;}@media (max-width:767px){.css-1nz60a6{padding:20px;}}.css-1nz60a6 .language{color:rgba(0,0,0,0.8);padding:5px 8px;position:absolute;border-radius:2px 0 3px 0;background:#f1f1f1;-webkit-transform:translate(-30px,-40px);-ms-transform:translate(-30px,-40px);transform:translate(-30px,-40px);font-size:13px;}@media (max-width:767px){.css-1nz60a6 .language{-webkit-transform:translate(-20px,-40px);-ms-transform:translate(-20px,-40px);transform:translate(-20px,-40px);font-size:12px;}}`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);``