Working with Group By Extensions – ROLLUP,CUBE,GROUPING SETS
Code:
-----------
use ramu;
create or replace table sales (product_id integer, retail_price real,
quantity integer, city varchar, state varchar);
insert into sales (product_id, retail_price, quantity, city, state) values
(1, 2.00, 1, 'SF', 'CA'),
(1, 2.00, 2, 'SJ', 'CA'),
(2, 5.00, 4, 'SF', 'CA'),
(2, 5.00, 8, 'SJ', 'CA'),
(2, 5.00, 16, 'Miami', 'FL'),
(2, 5.00, 32, 'Orlando', 'FL'),
(2, 5.00, 64, 'SJ', 'CA');
select * from sales;
select CITY,sum(quantity) from sales group by (CITY);
select STATE,sum(quantity) from sales group by (STATE);
select CITY,STATE,sum(quantity) from sales group by (CITY,STATE);
(select CITY,NULL as State,sum(quantity) from sales group by (CITY)) union all
(select NULL as CITY,STATE,sum(quantity) from sales group by (STATE));
--grouping set
select CITY,STATE,sum(quantity) from sales group by grouping sets (CITY,STATE);
--rollup
select CITY,STATE,sum(quantity) from sales group by rollup (STATE,CITY);
(STATE,CITY)
--------------------
(STATE,CITY)
(STATE)
()
(A,B,C)
---------
(A,B,C)
(A,B)
(A)
()
;
--cube
select CITY,STATE,sum(quantity) from sales group by cube (STATE,CITY);
(STATE,CITY)
-------------------
(STATE,CITY)
(CITY)
(STATE)
()
(A,B,C)
-------
(A,B,C)
(A,B)
(B,C)
(A,C)
(A)
(B)
(C)
()
Check this playlist for more AWS Projects in Big Data domain:
https://youtube.com/playlist?list=PLjfRmoYoxpNopPjdACgS5XTfdjyBcuGku
Видео Working with Group By Extensions – ROLLUP,CUBE,GROUPING SETS канала Knowledge Amplifier
-----------
use ramu;
create or replace table sales (product_id integer, retail_price real,
quantity integer, city varchar, state varchar);
insert into sales (product_id, retail_price, quantity, city, state) values
(1, 2.00, 1, 'SF', 'CA'),
(1, 2.00, 2, 'SJ', 'CA'),
(2, 5.00, 4, 'SF', 'CA'),
(2, 5.00, 8, 'SJ', 'CA'),
(2, 5.00, 16, 'Miami', 'FL'),
(2, 5.00, 32, 'Orlando', 'FL'),
(2, 5.00, 64, 'SJ', 'CA');
select * from sales;
select CITY,sum(quantity) from sales group by (CITY);
select STATE,sum(quantity) from sales group by (STATE);
select CITY,STATE,sum(quantity) from sales group by (CITY,STATE);
(select CITY,NULL as State,sum(quantity) from sales group by (CITY)) union all
(select NULL as CITY,STATE,sum(quantity) from sales group by (STATE));
--grouping set
select CITY,STATE,sum(quantity) from sales group by grouping sets (CITY,STATE);
--rollup
select CITY,STATE,sum(quantity) from sales group by rollup (STATE,CITY);
(STATE,CITY)
--------------------
(STATE,CITY)
(STATE)
()
(A,B,C)
---------
(A,B,C)
(A,B)
(A)
()
;
--cube
select CITY,STATE,sum(quantity) from sales group by cube (STATE,CITY);
(STATE,CITY)
-------------------
(STATE,CITY)
(CITY)
(STATE)
()
(A,B,C)
-------
(A,B,C)
(A,B)
(B,C)
(A,C)
(A)
(B)
(C)
()
Check this playlist for more AWS Projects in Big Data domain:
https://youtube.com/playlist?list=PLjfRmoYoxpNopPjdACgS5XTfdjyBcuGku
Видео Working with Group By Extensions – ROLLUP,CUBE,GROUPING SETS канала Knowledge Amplifier
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![Segmentation using Watershed Algorithm in Matlab | Practice Problem](https://i.ytimg.com/vi/uJquG-UI104/default.jpg)
![AWS S3 Bucket policies in-depth intuition](https://i.ytimg.com/vi/uKgIlFM6aP4/default.jpg)
![Demonstration of Facial Expression Recognition Using LBP Feature](https://i.ytimg.com/vi/i7EjCeBCsN4/default.jpg)
![Interactive Image Segmentation In-depth Intuition](https://i.ytimg.com/vi/l4n6LoNNpgE/default.jpg)
![Read CSV Data from External Stage & write in Permanent Snowflake Table using Snowflake Snowpark](https://i.ytimg.com/vi/JPQPsTA0N8E/default.jpg)
![Random Forest Classifier and Regressor (In-depth Intuition)](https://i.ytimg.com/vi/lvU2MApOTIs/default.jpg)
![How are k-means clustering algorithms sensitive to outliers?](https://i.ytimg.com/vi/SsmrcLAfbCA/default.jpg)
![Implementing Row Access Policies in Snowflake](https://i.ytimg.com/vi/GjLW9Vo-0_A/default.jpg)
![Apache Kafka Rebalance Listener & Implementing a database sink for Kafka](https://i.ytimg.com/vi/b3bS4KLpwQs/default.jpg)
![Processing Complex Type & Producing Messages to Topic using Faust](https://i.ytimg.com/vi/DpTJYtiYK9w/default.jpg)
![Automate the partition creation process in AWS Athena in-depth explanation](https://i.ytimg.com/vi/ybvpGJMUg9U/default.jpg)
![Data Retention Period in Snowflake](https://i.ytimg.com/vi/l04Gpn02pCM/default.jpg)
![In depth intuition on Manual Offset Commits & At Least Once Processing in Kafka Consumer](https://i.ytimg.com/vi/pavNd_LT9nI/default.jpg)
![Mastering Data Validation🔍 : Building a Metadata-Driven Framework for Error-Free Data🎯](https://i.ytimg.com/vi/Rp0RHsT0jIA/default.jpg)
![Build and automate Serverless DataLake using an AWS Glue , Lambda , Cloudwatch](https://i.ytimg.com/vi/3f7UY5R9Q9U/default.jpg)
![Error Handling in Kafka Producer In-Depth Intuition](https://i.ytimg.com/vi/Sq9Idany-_o/default.jpg)
![⚙️Automate Snowflake❄️ Reporting using Tasks, AWS Lambda , AWS SES 📧 | End-To-End Snowflake Project](https://i.ytimg.com/vi/PScK6OyL5RU/default.jpg)
![Building Real-Time Data Pipelines with Kafka , Faust & Snowflake](https://i.ytimg.com/vi/1ZQfXplyIO4/default.jpg)
![Strategies for Kafka Topic Partitioning when key=null](https://i.ytimg.com/vi/-eo4IPUshRo/default.jpg)
![Practice Problem on Texture Segmentation Using Texture Filters](https://i.ytimg.com/vi/2jwu5QLYkKQ/default.jpg)