Skip to content
Advertisement

Is there any syntactic sugar to using group by columns 1,2,3,…,n in SQL?

I know it isn’t a “good way of doing things”, but we use the following notations in many of our SQL queries :

I was wondering if there is an even more succinct way of writing it, e.g. GROUP BY 1-n (Group by col_1 to col_n)

Advertisement

Answer

Assume you have table with dozen or more columns

Consider below template (note below offset is zero-based) for BigQuery – should be perfect for POC type of work you mentioned

Below is dummy/simplistic example

with output

enter image description here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement