Complete SQL Topics for Data Analysis
-> https://t.me/sqlspecialist/523
Let's also learn about Window Functions today:
Window functions perform calculations across a set of table rows related to the current row. They are particularly useful for analytics and reporting.
#### ROW_NUMBER():
Assigns a unique number to each row within a partition of a result set.
SELECT column1, column2, ROW_NUMBER() OVER (PARTITION BY column3 ORDER BY column4) AS row_num#### RANK(), DENSE_RANK():
FROM table_name;
Assign ranks to rows based on a specified column, with optional handling of ties.
SELECT column1, column2, RANK() OVER (ORDER BY column3) AS rank_num#### LEAD(), LAG():
FROM table_name;
Access data from subsequent or previous rows within the result set.
SELECT column1, column2, LEAD(column2) OVER (ORDER BY column1) AS next_valueWindow functions provide powerful capabilities for comparative and sequential analysis in a dataset.
FROM table_name;
Share with credits: https://t.me/sqlspecialist
Hope it helps :)