Everything About Window Functions in SQL.

DataGeeks
5 min readJul 3, 2022

Another hot and most widely used concept in today’s advanced SQL. If you are a Data Analyst, Data Scientist, or Data engineer, you have encountered windows functions in your day-to-day work.
In this article, I am going to explain to you everything about the windows functions with examples.

Before jumping into the coding, we need to understand the Window in the window functions.

Window refers to the colloction of the related rows. e.g all the rows from the certain date , all the rows from a specific product or all the rows belongs to the country U.S.A.

A Window function is any function that operates over the window. Generally, window functions take two arguments one is the current row another one is the window in which that function operates

The syntax for window functions.

WINDOWS_FUNCTION(<column_name>) 
OVER (PARTITION BY <column1,column2....> ORDER BY column3 ASC|DESC)

Here we specify the window after the OVER and select the column names by which we want to group the related rows in the PARTITION BY.

We can classify the window functions into two main categories:
1. Rank related
2. General Window Function

--

--

DataGeeks
DataGeeks

Written by DataGeeks

A data couple, Having 15 years of combined experience in data and love to share the knowledge about Data

No responses yet