This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select customer_id, state_, profit_total, | |
LAG(profit_total) over(partition by state_ order by profit_total desc) as Lag_row | |
from customer_order_window; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select customer_id, state_, profit_total, | |
row_number() over(partition by state_ order by profit_total desc) as Rank_row | |
from customer_order_window; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select customer_id, state_, profit_total, | |
dense_rank() over(partition by state_ order by profit_total desc) as Rank_row | |
from customer_order_window; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select customer_id, state_, profit_total, | |
rank() over(partition by state_ order by profit_total desc) as Rank_row | |
from customer_order_window; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select customer_id, state_, profit_total, | |
sum(profit_total)over(partition by state_) as state_profit_total | |
from customer_order_window; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select customer_id, state_, profit_total, | |
max(profit_total) over( Partition by state_) as Max_profit, | |
min(profit_total) over( Partition by state_) as Min_profit | |
from customer_order_window; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select customer_id, state_, profit_total, | |
avg(profit_total) over(partition by state_) as AVG_ | |
from customer_order_window; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create table customer_order_window( | |
Customer_id Varchar(50) primary key unique, | |
customer_name varchar(50), | |
segment varchar(50), | |
age int, | |
country varchar(50), | |
city varchar(50), | |
state_ varchar(50), | |
postal_code bigint, | |
region varchar(50), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE UrBizEdge_Window_Functions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<window_function>(expression)OVER( | |
PARTITION BY <partition_list> | |
ORDER BY <order_list> | |
FROM <table_name>; |