From the course: Introduction to SQL Using Google BigQuery

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

GROUP BY clause

GROUP BY clause

- [Instructor] So far, we have looked at SQL statements to apply WHERE clauses to filter our products table before performing calculations on the dataset as a whole. However, what if we needed to compare calculations for multiple segments of data without running repetitive queries with different WHERE clauses? Enter the GROUP BY clause. We will use this super useful SQL technique to split up our products dataset into individual segments and return calculated metrics for each group. This is very efficient because we can do this in a single pass of data. To understand the mechanics of the GROUP BY clause, we can imagine splitting up our dataset into four smaller parts, each one with the same category name value. Let's say we wish to know how many products we have for each category. We can use a COUNT star in the SELECT part of our query and include the GROUP BY after the line where we see FROM wisdom_pets.products. The…

Contents