SlideShare a Scribd company logo
1 of 93
Advance SQL
Windows Functions
Eyal Trabelsi
What is a window function
https://blog.matters.tech/sql-window-functions-basics-e9a9fa17ce7e
Did they forget anything ?
NULLS !!!!!
• NULLS values are treated as their own group over
the partitioned columns.
NULLS !!!!!
• NULLS values are treated as their own group over
the partitioned columns.
• They sorted and ranked according to the NULLS
FIRST or NULLS LAST option.
NULLS !!!!!
• NULLS values are treated as their own group over
the partitioned columns.
• They sorted and ranked according to the NULLS
FIRST or NULLS LAST option.
• By default, NULL values are sorted and ranked last
in ASC ordering, and sorted and ranked first in
DESC ordering.
NULLS !!!!!
Supported window functions
Supported window functions
• Window function are vendor ‘ dependent!!!!
Supported window functions
• Window function are vendor ‘ dependent!!!!
• Most vendors support the all the basic window functions
like avg, min, max, count, sum, lead, lag, rank etc.
Supported window functions
• Window function are vendor ‘ dependent!!!!
• Most vendors support the all the basic window functions
like avg, min, max, count, sum, lead, lag, rank etc.
• These are the vendor specific supported window
functions:
Supported window functions
• Window function are vendor ‘ dependent!!!!
• Most vendors support the all the basic window functions
like avg, min, max, count, sum, lead, lag, rank etc.
• These are the vendor specific supported window
functions:
Our Business use case
Lets say we have the following events table
Our Business use case
Our Business use case
Event_id time user_id type click_num
1 18:00 1 a 2
2 18:20 1 a 3
3 18:59 1 b 4
4 18:00 2 b 1
Lets say we have the following events table
Calculating Cumulative sum via sum
Calculating Cumulative sum via sum
Event_id time user_id type click_num cumsum
1 18:0
0
1 a 2 2
2 18:2
0
1 a 3 5
3 18:5
9
1 b 4 9
4 18:0
0
2 b 1 1
Calculating Cumulative sum via sum
Calculating Cumulative sum via sum
SELECT event_id,
time,
user_id,
type,
sum(click_num) over (PARTITION BY user_id ORDER BY time
ROWS UNBOUNDED PRECEDING)
FROM t
Calculating Cumulative sum via sum
Calculating Cumulative sum via sum
DEFAULTS!!!
Calculating Cumulative sum via sum
DEFAULTS!!!
Calculating Cumulative sum via sum
• Calculate cumulative sum of lead per month
• Calculate cumulative sum of orders’ amount per store
Calculate Growth
Calculate Growth
Event_id time user_id type click_num growth
1 18:0
0
1 a 2 NULL
2 18:2
0
1 b 3 1/2
3 18:5
9
1 a 4 1/3
4 18:0
0
2 b 1 NULL
Calculate Growth
Calculate Growth
SELECT event_id,
time,
user_id,
type,
lag(num_click) over (PARTITION BY user_id ORDER BY time) AS
last_num_click,
(num_click - last_num_click) / last_num_click
FROM t
Calculate Growth
SELECT event_id,
time,
user_id,
type,
lag(num_click) over (PARTITION BY user_id ORDER BY time) AS
last_num_click,
(num_click - last_num_click) / last_num_click
FROM t
*
Calculate Growth
• Calculate growth of accounts month after month
• Calculate growth of orders amount per store month after month
• Calculate growth of orders amount per store and opportunity
Calculate Growth
• Calculate growth of accounts month after month
• Calculate growth of orders amount per store month after month
• Calculate growth of orders amount per store and opportunity HARD :P
Indicate the first event for each user
Indicate the first event for each user
Event_id time user_id type first
1 18:00 1 a 1
2 18:20 1 b 0
3 18:59 1 a 0
4 18:00 2 b 1
Indicate the first event for each user
Indicate the first event for each user
SELECT event_id,
time,
user_id,
type
floor(1/ row_number() over (PARTITION BY user_id ORDER BY time))
FROM t
Indicate the first row template
Indicate the first row template
SELECT c1,
c2,
floor(1/ row_number() over (PARTITION BY c1 ORDER BY c2))
FROM t
Indicate the first template use-cases
Indicate the first template use-cases
• Our analysis need to indicate rank without changing.
granularity (filtering for example or summation of sub
granularity).
Indicate the first template use-cases
• Our analysis need to indicate rank without changing.
granularity (filtering for example or summation of sub
granularity).
• When we want to consolidate tables which indicate
changes and the source doesn’t support it. For example
table which indicate transitions to plans might miss the
first plans.
Indicate the first template use-cases
• Our analysis need to indicate rank without changing.
granularity (filtering for example or summation of sub
granularity).
• When we want to consolidate tables which indicate
changes and the source doesn’t support it. For example
table which indicate transitions to plans might miss the
first plans.
• Our query goal is not clear whether changing granularity
is needed.
Indicate the first template questions
• Show indicator on the first segment touch point on the store
• Show indicator for the first event of product change for store
Now for more
“complicated”
patterns
Creating session for user within 30 min
Creating session for user within 30 min
Event_id time user_id type session
1 18:00 1 a 1
2 18:20 1 b 1
3 18:59 1 a 2
4 18:00 2 b 1
Creating session for user within 30 min
Creating session for user within 30 min
https://blog.modeanalytics.com/finding-user-sessions-sql/
Creating session template
Creating session template
SELECT *,
SUM(new_session) over (PARTITION BY user_id ORDER BY time) AS new_session
FROM ( SELECT *
CASE WHEN (time - LEAD(time) over (PARTITION BY user_id ORDER BY time)) >
<INTERVAL>
THEN 1
ELSE 0
END AS new_session
FROM t
)
Creating session with condition
Creating session with condition
Lets say we don’t want to sessionize events with type b
Creating session with condition
Event_id time user_id type session
1 18:00 1 a 1
2 18:20 1 b
3 18:59 1 a 2
4 18:00 2 a 1
Lets say we don’t want to sessionize events with type b
Creating session with condition
Creating session with condition
Creating session with condition
SELECT *,
SUM(new_session) over (PARTITION BY user_id ,condition ORDER BY time) AS new_session
FROM ( SELECT *
CASE WHEN (time - LEAD(time) over (PARTITION BY user_id,condition ORDER BY time)) >
<INTERVAL>
THEN 1
ELSE 0
END AS new_session
FROM t
)
Creating session with condition
template use-cases
• Our analysis need to indicate rank without changing.
granularity (filtering for example).
Finding Series length
Finding Series length
https://www.youtube.com/watch?v=mgipNdAgQ3o&t
=1070s%3Fstart=20:08&end=24:34
Finding Series length use-cases
Finding Series length use-cases
• Our analysis need to check sequence of improvement:
Finding Series length questions
• find the largest sequence of month with increase in lead creation
• find the largest sequence of month with decrease in ticket for product x
• find the difference in sequence of month with decrease in ticket for product
x after bug was fixed
Time decay template use-cases
Our analysis has time related importance calculation
• Calculated recommended movie , if I saw a movie a week
ago it will probably be more relevant to my interest than
movie I saw 5 years ago .
Our Business use case
Event_id time user_id package
1 1/1/18 1 a
2 1/2/18 1 b
3 1/6/18 1 a
4 1/7/18 1 c
Lets say we have the following package change table
Join on time interval
Join on time interval
Lets say we have the following package change
table
Join on time interval
Event_id From_time To_time user_id package
1 1/1/18 1/2/18 1 a
2 1/2/18 1/6/18 1 b
3 1/6/18 1/7/18 1 a
4 1/7/18 NULL 1 c
Lets say we have the following package change
table
Join on time interval
Event_id From_time To_time user_id package
1 1/1/18 1/2/18 1 a
2 1/2/18 1/6/18 1 b
3 1/6/18 1/7/18 1 a
4 1/7/18 1/1/99 1 c
Lets say we have the following package change
table
*
Join on time interval
*
Join on time interval
SELECT event_id,
type,
user_id,
package,
time AS from_time,
ISNULL(LEAD(time) over (PARTITION BY user_id ORDER BY time)),’1/1/99’)
AS to_time
FROM t
Join on time interval template
Join on time interval template
SELECT c1,
c2 AS from_time,
ISNULL(LEAD(c2) over (PARTITION BY c1 ORDER BY c2)),’2999-01-01’)
AS to_time
FROM t
Join on time interval template use-cases
Join on time interval template use-cases
• We need to join between two events which didn’t occur in
the exact same time
Join on time interval template use-cases
• We need to join between two events which didn’t occur in
the exact same time
• When we want to create “contracts” when we have
events only.
Join on time interval template use-cases
• We need to join between two events which didn’t occur in
the exact same time
• When we want to create “contracts” when we have
events only.
• When we want to consolidate two “contracts” from
different sources.
Join on time interval template questions
• Connecting orders to the browsing session which resulted in the
purchase
• For each month understand which package the customer is.
Our Business use case
Event_id time user_id type click_num
1 18:00 1 a 2
2 18:20 1 a 3
3 18:59 1 b 4
3 18:59 1 b 4
Lets say we have the following events table
Deduplication
Deduplication
Event_id time user_id type click_num
1 18:00 1 a 2
2 18:20 1 a 3
3 18:59 1 b 4
Deduplication
Deduplication
SELECT event_id,
time,
user_id,
type,
click_num
FROM (SELECT *
row_number() over (PARTITION BY event_id ORDER BY time)) AS
rnk
FROM t)
WHERE rnk=1
Deduplication template
Deduplication template
SELECT *
FROM (SELECT c1,
c2,
row_number() over (PARTITION BY pk ORDER BY c2)) AS rnk
FROM t)
WHERE rnk=1
Deduplication template questions
• Return all won opportunities except ones which occur
in the same month (keep only last)
Window Functions Rocks
Window Functions Rocks

More Related Content

What's hot

Systems Thinking, Human Body Metaphor, and Causal Loop Diagramming
Systems Thinking, Human Body Metaphor, and Causal Loop DiagrammingSystems Thinking, Human Body Metaphor, and Causal Loop Diagramming
Systems Thinking, Human Body Metaphor, and Causal Loop DiagrammingJay Hays
 
Asking the right questions a guide to critical thinking by m. neil browne, st...
Asking the right questions a guide to critical thinking by m. neil browne, st...Asking the right questions a guide to critical thinking by m. neil browne, st...
Asking the right questions a guide to critical thinking by m. neil browne, st...Hồng Hạnh
 
20 Facebook, Twitter, Linkedin & Pinterest Features You Didn't Know Existed (...
20 Facebook, Twitter, Linkedin & Pinterest Features You Didn't Know Existed (...20 Facebook, Twitter, Linkedin & Pinterest Features You Didn't Know Existed (...
20 Facebook, Twitter, Linkedin & Pinterest Features You Didn't Know Existed (...HubSpot
 
12 Secrets of Making Every Presentation Fun, Engaging and Enjoyable
12 Secrets of Making Every Presentation Fun, Engaging and Enjoyable12 Secrets of Making Every Presentation Fun, Engaging and Enjoyable
12 Secrets of Making Every Presentation Fun, Engaging and EnjoyableSketchBubble
 
Pricing Strategy Powerpoint Presentation Slides
Pricing Strategy Powerpoint Presentation SlidesPricing Strategy Powerpoint Presentation Slides
Pricing Strategy Powerpoint Presentation SlidesSlideTeam
 
Incorporating Technology - Report
Incorporating Technology - ReportIncorporating Technology - Report
Incorporating Technology - ReportJuan Escallon
 
Inspired Storytelling: Engaging People & Moving Them To Action
Inspired Storytelling: Engaging People & Moving Them To ActionInspired Storytelling: Engaging People & Moving Them To Action
Inspired Storytelling: Engaging People & Moving Them To ActionKelsey Ruger
 
How To Start an Info Publishing Business
How To Start an Info Publishing BusinessHow To Start an Info Publishing Business
How To Start an Info Publishing BusinessPerry Belcher
 

What's hot (9)

Systems Thinking, Human Body Metaphor, and Causal Loop Diagramming
Systems Thinking, Human Body Metaphor, and Causal Loop DiagrammingSystems Thinking, Human Body Metaphor, and Causal Loop Diagramming
Systems Thinking, Human Body Metaphor, and Causal Loop Diagramming
 
Asking the right questions a guide to critical thinking by m. neil browne, st...
Asking the right questions a guide to critical thinking by m. neil browne, st...Asking the right questions a guide to critical thinking by m. neil browne, st...
Asking the right questions a guide to critical thinking by m. neil browne, st...
 
Setting outlook express vtechpk
Setting outlook express  vtechpk Setting outlook express  vtechpk
Setting outlook express vtechpk
 
20 Facebook, Twitter, Linkedin & Pinterest Features You Didn't Know Existed (...
20 Facebook, Twitter, Linkedin & Pinterest Features You Didn't Know Existed (...20 Facebook, Twitter, Linkedin & Pinterest Features You Didn't Know Existed (...
20 Facebook, Twitter, Linkedin & Pinterest Features You Didn't Know Existed (...
 
12 Secrets of Making Every Presentation Fun, Engaging and Enjoyable
12 Secrets of Making Every Presentation Fun, Engaging and Enjoyable12 Secrets of Making Every Presentation Fun, Engaging and Enjoyable
12 Secrets of Making Every Presentation Fun, Engaging and Enjoyable
 
Pricing Strategy Powerpoint Presentation Slides
Pricing Strategy Powerpoint Presentation SlidesPricing Strategy Powerpoint Presentation Slides
Pricing Strategy Powerpoint Presentation Slides
 
Incorporating Technology - Report
Incorporating Technology - ReportIncorporating Technology - Report
Incorporating Technology - Report
 
Inspired Storytelling: Engaging People & Moving Them To Action
Inspired Storytelling: Engaging People & Moving Them To ActionInspired Storytelling: Engaging People & Moving Them To Action
Inspired Storytelling: Engaging People & Moving Them To Action
 
How To Start an Info Publishing Business
How To Start an Info Publishing BusinessHow To Start an Info Publishing Business
How To Start an Info Publishing Business
 

Similar to Advance sql - window functions patterns and tricks

In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engineWO Community
 
Scalable Event Processing with WSO2CEP @ WSO2Con2015eu
Scalable Event Processing with WSO2CEP @  WSO2Con2015euScalable Event Processing with WSO2CEP @  WSO2Con2015eu
Scalable Event Processing with WSO2CEP @ WSO2Con2015euSriskandarajah Suhothayan
 
3 interaction and_state_modeling
3 interaction and_state_modeling3 interaction and_state_modeling
3 interaction and_state_modelingMinal Maniar
 
Augmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML ToolkitAugmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML ToolkitDatabricks
 
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...Ontico
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#Hawkman Academy
 
Simplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functionsSimplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functionsClayton Groom
 
Complex Event Processor 3.0.0 - An overview of upcoming features
Complex Event Processor 3.0.0 - An overview of upcoming features Complex Event Processor 3.0.0 - An overview of upcoming features
Complex Event Processor 3.0.0 - An overview of upcoming features WSO2
 
Parallel Complex Event Processing
Parallel Complex Event ProcessingParallel Complex Event Processing
Parallel Complex Event ProcessingKarol Grzegorczyk
 
Introduction to Cellular Manufacturing - ADDVALUE - Nilesh Arora
Introduction to Cellular Manufacturing - ADDVALUE - Nilesh AroraIntroduction to Cellular Manufacturing - ADDVALUE - Nilesh Arora
Introduction to Cellular Manufacturing - ADDVALUE - Nilesh AroraADD VALUE CONSULTING Inc
 
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...Harry McLaren
 
TSAR (TimeSeries AggregatoR) Tech Talk
TSAR (TimeSeries AggregatoR) Tech TalkTSAR (TimeSeries AggregatoR) Tech Talk
TSAR (TimeSeries AggregatoR) Tech TalkAnirudh Todi
 
Refactoring at Large
Refactoring at LargeRefactoring at Large
Refactoring at LargeDanilo Sato
 
Obiee interview questions and answers faq
Obiee interview questions and answers faqObiee interview questions and answers faq
Obiee interview questions and answers faqmaheshboggula
 
Stop Flying Blind! Quantifying Risk with Monte Carlo Simulation
Stop Flying Blind! Quantifying Risk with Monte Carlo SimulationStop Flying Blind! Quantifying Risk with Monte Carlo Simulation
Stop Flying Blind! Quantifying Risk with Monte Carlo SimulationSam McAfee
 
Data Platform at Twitter: Enabling Real-time & Batch Analytics at Scale
Data Platform at Twitter: Enabling Real-time & Batch Analytics at ScaleData Platform at Twitter: Enabling Real-time & Batch Analytics at Scale
Data Platform at Twitter: Enabling Real-time & Batch Analytics at ScaleSriram Krishnan
 
How to get Automated Testing "Done"
How to get Automated Testing "Done"How to get Automated Testing "Done"
How to get Automated Testing "Done"TEST Huddle
 

Similar to Advance sql - window functions patterns and tricks (20)

In memory OLAP engine
In memory OLAP engineIn memory OLAP engine
In memory OLAP engine
 
Scalable Event Processing with WSO2CEP @ WSO2Con2015eu
Scalable Event Processing with WSO2CEP @  WSO2Con2015euScalable Event Processing with WSO2CEP @  WSO2Con2015eu
Scalable Event Processing with WSO2CEP @ WSO2Con2015eu
 
3 interaction and_state_modeling
3 interaction and_state_modeling3 interaction and_state_modeling
3 interaction and_state_modeling
 
Augmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML ToolkitAugmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML Toolkit
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
Simplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functionsSimplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functions
 
When Should I Use Simulation?
When Should I Use Simulation?When Should I Use Simulation?
When Should I Use Simulation?
 
Complex Event Processor 3.0.0 - An overview of upcoming features
Complex Event Processor 3.0.0 - An overview of upcoming features Complex Event Processor 3.0.0 - An overview of upcoming features
Complex Event Processor 3.0.0 - An overview of upcoming features
 
Parallel Complex Event Processing
Parallel Complex Event ProcessingParallel Complex Event Processing
Parallel Complex Event Processing
 
Introduction to Cellular Manufacturing - ADDVALUE - Nilesh Arora
Introduction to Cellular Manufacturing - ADDVALUE - Nilesh AroraIntroduction to Cellular Manufacturing - ADDVALUE - Nilesh Arora
Introduction to Cellular Manufacturing - ADDVALUE - Nilesh Arora
 
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...
 
TSAR (TimeSeries AggregatoR) Tech Talk
TSAR (TimeSeries AggregatoR) Tech TalkTSAR (TimeSeries AggregatoR) Tech Talk
TSAR (TimeSeries AggregatoR) Tech Talk
 
Tsar tech talk
Tsar tech talkTsar tech talk
Tsar tech talk
 
Refactoring at Large
Refactoring at LargeRefactoring at Large
Refactoring at Large
 
Obiee interview questions and answers faq
Obiee interview questions and answers faqObiee interview questions and answers faq
Obiee interview questions and answers faq
 
Stop Flying Blind! Quantifying Risk with Monte Carlo Simulation
Stop Flying Blind! Quantifying Risk with Monte Carlo SimulationStop Flying Blind! Quantifying Risk with Monte Carlo Simulation
Stop Flying Blind! Quantifying Risk with Monte Carlo Simulation
 
Data Platform at Twitter: Enabling Real-time & Batch Analytics at Scale
Data Platform at Twitter: Enabling Real-time & Batch Analytics at ScaleData Platform at Twitter: Enabling Real-time & Batch Analytics at Scale
Data Platform at Twitter: Enabling Real-time & Batch Analytics at Scale
 
How to get Automated Testing "Done"
How to get Automated Testing "Done"How to get Automated Testing "Done"
How to get Automated Testing "Done"
 

More from Eyal Trabelsi

Structuring and packaging your python project
Structuring and packaging your python projectStructuring and packaging your python project
Structuring and packaging your python projectEyal Trabelsi
 
Getting to know any dataset
Getting to know any datasetGetting to know any dataset
Getting to know any datasetEyal Trabelsi
 
Make Terminal Fun Again
Make Terminal Fun AgainMake Terminal Fun Again
Make Terminal Fun AgainEyal Trabelsi
 
Advance sql session - strings
Advance sql  session - stringsAdvance sql  session - strings
Advance sql session - stringsEyal Trabelsi
 
Bring sanity back to sql (advance sql)
Bring sanity back to sql (advance sql)Bring sanity back to sql (advance sql)
Bring sanity back to sql (advance sql)Eyal Trabelsi
 
Seminar - Similarity Joins in SQL (performance and semantic joins)
Seminar - Similarity Joins in SQL (performance and semantic joins)Seminar - Similarity Joins in SQL (performance and semantic joins)
Seminar - Similarity Joins in SQL (performance and semantic joins)Eyal Trabelsi
 

More from Eyal Trabelsi (6)

Structuring and packaging your python project
Structuring and packaging your python projectStructuring and packaging your python project
Structuring and packaging your python project
 
Getting to know any dataset
Getting to know any datasetGetting to know any dataset
Getting to know any dataset
 
Make Terminal Fun Again
Make Terminal Fun AgainMake Terminal Fun Again
Make Terminal Fun Again
 
Advance sql session - strings
Advance sql  session - stringsAdvance sql  session - strings
Advance sql session - strings
 
Bring sanity back to sql (advance sql)
Bring sanity back to sql (advance sql)Bring sanity back to sql (advance sql)
Bring sanity back to sql (advance sql)
 
Seminar - Similarity Joins in SQL (performance and semantic joins)
Seminar - Similarity Joins in SQL (performance and semantic joins)Seminar - Similarity Joins in SQL (performance and semantic joins)
Seminar - Similarity Joins in SQL (performance and semantic joins)
 

Recently uploaded

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

Advance sql - window functions patterns and tricks

Editor's Notes

  1. Spark supported window functions: https://jaceklaskowski.gitbooks.io/mastering-spark-sql/spark-sql-functions-windows.html Redshift supported window functions: https://docs.aws.amazon.com/redshift/latest/dg/c_Window_functions.html
  2. TODO cummulitive sum
  3. Redshift defaults- https://docs.aws.amazon.com/redshift/latest/dg/r_Window_function_synopsis.html Spark defaults - https://stackoverflow.com/questions/47130030/whats-the-default-window-frame-for-window-functions
  4. Nice trick: https://blog.jooq.org/2016/10/31/a-little-known-sql-feature-use-logical-windowing-to-aggregate-sliding-ranges/ Not supported in most engines
  5. Example segment
  6. Example segment
  7. Example segment
  8. Example segment
  9. Example segment
  10. Example segment
  11. Can be used for sessionization as well
  12. - Link is https://www.youtube.com/watch?v=mgipNdAgQ3o&t=1070s%3Fstart=20:08&end=24:34