-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4-2.sql
More file actions
34 lines (31 loc) · 864 Bytes
/
4-2.sql
File metadata and controls
34 lines (31 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-- Enhanced aggregations with grouping sentences
select
ordermonthyear as OrderMonth,
productcategory as Category,
sum(saleamount) as TotalSales
from
sales_all_years
where
lower(ordermonthyear) != 'ordermonthyear'
group by
ordermonthyear,
productcategory
-- enhancing
grouping sets
(ordermonthyear, productcategory) -- same as union of two queries with group by of a and b separately
-- get both individually and the combo. Identify which using GROUPING__ID
select
ordermonthyear as OrderMonth,
productcategory as Category,
GROUPING__ID as Grp,
sum(saleamount) as TotalSales
from
sales_all_years
where
lower(ordermonthyear) != 'ordermonthyear'
group by
ordermonthyear,
productcategory
-- enhancing
grouping sets
((ordermonthyear, productcategory), ordermonthyear, productcategory)