Skip to content

Instantly share code, notes, and snippets.

View kiddojazz's full-sized avatar
🎯
Focusing

Temidayo Omoniyi kiddojazz

🎯
Focusing
View GitHub Profile
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;
select customer_id, state_, profit_total,
row_number() over(partition by state_ order by profit_total desc) as Rank_row
from customer_order_window;
select customer_id, state_, profit_total,
dense_rank() over(partition by state_ order by profit_total desc) as Rank_row
from customer_order_window;
select customer_id, state_, profit_total,
rank() over(partition by state_ order by profit_total desc) as Rank_row
from customer_order_window;
select customer_id, state_, profit_total,
sum(profit_total)over(partition by state_) as state_profit_total
from customer_order_window;
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;
select customer_id, state_, profit_total,
avg(profit_total) over(partition by state_) as AVG_
from customer_order_window;
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),
CREATE DATABASE UrBizEdge_Window_Functions;
<window_function>(expression)OVER(
PARTITION BY <partition_list>
ORDER BY <order_list>
FROM <table_name>;