interview preparation

Common Window Functions

  1. Ranking
    • ROW_NUMBER(): Assigns a unique number to each row.
    • RANK(): Assigns ranks; ties get the same rank.
    • DENSE_RANK(): Similar to RANK(), but no gaps between ranks.
  2. Aggregates:
    • SUM(), AVG(), MIN(), MAX(), COUNT(): Works across the window.
  3. Analytics:
    • LAG() and LEAD(): Access values from previous or next rows.
    • FIRST_VALUE() and LAST_VALUE(): Get the first or last value in the window.
  4. Percentages:
    • PERCENT_RANK(): Rank as a percentage.
    • NTILE(n): Divides rows into n buckets.