GROUP BY clause
Description
The
GROUP BYclause identifies the grouping columns for the query. Grouping columns must be declared when the query computes aggregates with standard functions such asSUM,AVG, andCOUNT. (Redshift SQL Language Reference GROUP BY Clause)
The GROUP BY clause is fully supported in Snowflake.
Grammar Syntax
GROUP BY group_by_clause [, ...]
group_by_clause := {
expr |
GROUPING SETS ( () | group_by_clause [, ...] ) |
ROLLUP ( expr [, ...] ) |
CUBE ( expr [, ...] )
}Sample Source Patterns
Grouping sets
Input Code:
MANAGER_ID
TOTAL_EMPLOYEES
100
1
101
3
102
2
103
3
104
3
null
1
null
13
Output Code:
MANAGER_ID
TOTAL_EMPLOYEES
100
1
101
3
102
2
103
3
104
3
null
1
null
13
Group by Cube
Input Code:
MANAGER_ID
TOTAL_EMPLOYEES
100
1
101
3
102
2
103
3
104
3
null
1
null
13
Output Code:
MANAGER_ID
TOTAL_EMPLOYEES
100
1
101
3
102
2
103
3
104
3
null
1
null
13
Group by Rollup
Input Code:
MANAGER_ID
TOTAL_EMPLOYEES
100
1
101
3
102
2
103
3
104
3
null
1
null
13
Output Code:
MANAGER_ID
TOTAL_EMPLOYEES
100
1
101
3
102
2
103
3
104
3
null
1
null
13
Related EWIs
There are no known issues.
Last updated
