0% found this document useful (0 votes)
2 views5 pages

Day - 27 - SQL - Window Functions in SQL

The document discusses window functions in SQL, which allow for calculations across a set of table rows related to the current row. It provides examples for assigning unique row numbers, calculating running totals, and ranking products within categories. These functions are useful for tasks such as ranking and calculating totals and percentages.
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)
2 views5 pages

Day - 27 - SQL - Window Functions in SQL

The document discusses window functions in SQL, which allow for calculations across a set of table rows related to the current row. It provides examples for assigning unique row numbers, calculating running totals, and ranking products within categories. These functions are useful for tasks such as ranking and calculating totals and percentages.
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

Day – 27 :

Window Functions in
SQL

Course created by Satish Dhawale | [Link]


Window functions perform calculations across a set of
table rows related to the current row. They are useful for
Window functions ranking, calculating running totals, percentages, and much
more.
Assign a unique row
number to each product
within the same category.

SELECT
product_name,
category,
price,
ROW_NUMBER() OVER (PARTITION BY
category ORDER BY price DESC) AS
row_num
FROM products;
Calculate the running
total of prices across
all products.

SELECT
product_name,
price,
SUM(price) OVER (ORDER BY price
DESC) AS running_total
FROM products;
Ranking Window
Function

SELECT
product_name,
category,
price,
DENSE_RANK() OVER
(PARTITION BY category ORDER BY price
DESC) AS Ranking
FROM products;

You might also like