0% found this document useful (0 votes)
8 views9 pages

SQL_Window_Functions__1715134116

Window Functions enable calculations across related rows without a GROUP BY clause, allowing for running totals, moving averages, and cumulative sums while maintaining the original data structure. The document outlines the components of a window function, including the function type, expression, optional clauses for partitioning, ordering, and row specifications. An example demonstrates calculating a running total of revenue for products, showcasing the cumulative sum without altering the original dataset.

Uploaded by

priyesh.infosec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views9 pages

SQL_Window_Functions__1715134116

Window Functions enable calculations across related rows without a GROUP BY clause, allowing for running totals, moving averages, and cumulative sums while maintaining the original data structure. The document outlines the components of a window function, including the function type, expression, optional clauses for partitioning, ordering, and row specifications. An example demonstrates calculating a running total of revenue for products, showcasing the cumulative sum without altering the original dataset.

Uploaded by

priyesh.infosec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

@INSIGHTSxDESIGN

KEY ANALYST
SKILLS
Window Functions allow you to perform
calculations across a set of rows that are
related to the current row, without the need
for a GROUP BY clause. This means you can
calculate running totals, moving averages,
cumulative sums, and much more, all while
preserving the original data structure.
1. <window_function>: This is the actual window function you
want to use, such as ROW_NUMBER(), RANK(),
DENSE_RANK(), NTILE(), SUM(), AVG(), MIN(), MAX(), etc.
2. <expression>: The column or expression on which you want
to perform the window function.
3. PARTITION BY: This clause is optional and is used to divide
the result set into partitions to which the window function will
be applied.
4. ORDER BY: This clause is also optional and is used to specify
the order in which the rows in the result set are ranked.
5. ROWS <frame_specification>: This clause is also optional
and is used to define the range of rows within a partition that
the window function will operate on.
Suppose we have a table called 'sales'
with the following data:
Let's use the example Window Function
query to calculate the running total of
revenue for each product, ordered by
date:
After applying the Window Function, the
resulting table looks like this:

The running_total column shows the


cumulative sum of the revenue for each
product_id, ordered by date, without
changing the original data structure.
@INSIGHTSxDESIGN

You might also like