interview preparation
Common Window Functions
- Ranking
ROW_NUMBER()
: Assigns a unique number to each row.RANK()
: Assigns ranks; ties get the same rank.DENSE_RANK()
: Similar toRANK()
, but no gaps between ranks.
- Aggregates:
SUM()
,AVG()
,MIN()
,MAX()
,COUNT()
: Works across the window.
- Analytics:
LAG()
andLEAD()
: Access values from previous or next rows.FIRST_VALUE()
andLAST_VALUE()
: Get the first or last value in the window.
- Percentages:
PERCENT_RANK()
: Rank as a percentage.NTILE(n)
: Divides rows inton
buckets.