Sunday, May 17, 2026

Window Functions (79–88)

 

Window Functions (79–88)

  1. What is a window function?
    It performs calculations across rows without collapsing them.
  2. What is ROW_NUMBER()?
    Assigns unique row number.
  3. What is RANK()?
    Assigns rank with gaps for ties.
  4. What is DENSE_RANK()?
    Assigns rank without gaps.
  5. Difference between RANK and DENSE_RANK?
    RANK skips numbers after tie; DENSE_RANK does not.
  6. What is PARTITION BY?
    Divides result set into groups for window functions.
  7. Find highest salary in each department.
    Use RANK() with PARTITION BY dept.
  8. What is LEAD()?
    Fetches next row value.
  9. What is LAG()?
    Fetches previous row value.
  10. Scenario: Compare current month sales with previous month.
    Use LAG(sales).