Skip to main content

Command Palette

Search for a command to run...

Using GROUP BY ALL in BigQuery

Updated
1 min read
Using GROUP BY ALL in BigQuery
C

Senior Data Engineer • Contractor / Freelancer • GCP & AWS Certified

Featured in other database systems, the GROUP BY ALL has been announced in preview for BigQuery as well.

This will allow us to not enumerate all the non-aggregated columns when performing aggregates.

It's definitely better than GROUP BY 1,2,3 which would fail once we'd change the list of columns we'd like to group by. Overall, I find it a useful shorthand when exploring or debugging.

Here's an example of how it looks.


SELECT country, sell_date, SUM(sales) AS total_sales

FROM input_data

-- new
GROUP BY ALL

-- instead of
-- GROUP BY country, sell_date

Found it useful? Check out to my Analytics newsletter at notjustsql.com.

Practical SQL

Part 1 of 50

Short, practical posts on SQL and BigQuery — from core language features to advanced query patterns. A reference for data practitioners at every level.

More from this blog

D

Datawise — SQL, BigQuery & Python for Data Engineers

205 posts

Data Engineer with a passion for transforming complex data landscapes into insightful stories. Here on my blog, I share insights, challenges, and the ever-evolving dance of technology and business.