SQL Windows Functions Explained like you are 5!

SQL windows are essential for a data analyst. You must learn them. Learn here in 2 min.

A thread..⬇️ Image
So what are Windows Functions: — Summarize a particular table over a particular column(thus creating a window) and calculate the result using different functions(mentioned above)
Functions are divided into two types: the ranking and value functions. The ranking functions are used to simply assign numbers to the existing rows according to some requirements, and value functions are used to copy values from other rows to other rows within the defined windows
USE CASE: Suppose you have financial data of companies and you have recently started investing You have the basic idea that you will only invest in companies that are in the Top 3 of their business category. Image
That’s where the importance of windows functions comes in. You will use the windows rank function(See the first image) and fetch on top 3 companies by the market cap of their business. (See the code below). Image
Ranking Window Functions :
Ranking functions are, RANK(), DENSE_RANK(), ROW_NUMBER().
The below image tells you the difference between these. Image
Value Window Functions :
Value functions are, Lead() , Lag().

LAG() — The LAG() function allows access to a value stored in a different row above the current row. The row above may be adjacent or some number of rows above, as sorted by a specified column or set of columns. Image
LEAD() — Lead() is similar to Lag(). Whereas Lag() accesses a value stored in a row above, Lead() accesses a value stored in a row below. Image
That’s It. I hope it helps you in your journey of becoming a #dataanalyst. I have used and used most of these websites not just for practice but for revision of multiple aspects of the data analytics journey.

Do follow @doingwithdata for more updates on #dataanalytics.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with doingwithdata

doingwithdata Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(