Window Functions (79–88)
-
What is a window function?
It performs calculations across rows without collapsing them.
-
What is ROW_NUMBER()?
Assigns unique row number.
-
What is RANK()?
Assigns rank with gaps for ties.
-
What is DENSE_RANK()?
Assigns rank without gaps.
-
Difference between RANK and DENSE_RANK?
RANK skips numbers after tie; DENSE_RANK does not.
-
What is PARTITION BY?
Divides result set into groups for window functions.
-
Find highest salary in each department.
Use RANK() with PARTITION BY dept.
-
What is LEAD()?
Fetches next row value.
-
What is LAG()?
Fetches previous row value.
-
Scenario: Compare current month sales with previous month.
Use LAG(sales).
No comments:
Post a Comment