From the course: Advanced SQL: Logical Query Processing, Part 2
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Grouping sets - SQL Tutorial
From the course: Advanced SQL: Logical Query Processing, Part 2
Grouping sets
- [Instructor] A very common data analysis requirement is to present data in multiple aggregation levels. For example, how many animals do we have per species and breed, only per species, and overall? Oftentimes, these aggregation levels are temporal in nature. What's our annual, quarterly, monthly, weekly, daily, hourly, and secondly revenue? There are several ways we can achieve this. We can use subqueries, window functions, and even set operators. But there's an even better way, one that unfortunately I rarely see used. We need to write a query to show the number of annual, monthly, and overall adoptions. Let's start with an Eve approach by writing three separate queries, one that groups by year and month, one that groups only by year, and one that counts all adoptions overall. Typically, when we write queries that group by the whole table, we do so by simply omitting the group by clause. Did you know it's only…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.