Bird
0
0

What does the RANK() OVER (PARTITION BY category ORDER BY price DESC) window function do in PostgreSQL?

easy📝 Conceptual Q1 of 15
PostgreSQL - Window Functions in PostgreSQL
What does the RANK() OVER (PARTITION BY category ORDER BY price DESC) window function do in PostgreSQL?
AAssigns a rank to each row within each category, with ties receiving the same rank
BCounts the number of rows in each category
CCalculates the cumulative sum of prices within each category
DReturns the total number of categories in the table
Step-by-Step Solution
Solution:
  1. Step 1: Understand RANK() function behavior

    The RANK() function assigns ranks to rows ordered by a specified column, giving the same rank to ties.
  2. Step 2: Analyze PARTITION BY usage

    Partitioning by category means ranking restarts for each category group separately.
  3. Final Answer:

    Assigns a rank to each row within each category, with ties receiving the same rank -> Option A
  4. Quick Check:

    RANK() with PARTITION BY = Assign ranks with ties [OK]
Quick Trick: RANK() gives same rank to ties within partitions [OK]
Common Mistakes:
  • Confusing RANK() with ROW_NUMBER() which does not tie ranks
  • Thinking it counts rows instead of ranking
  • Ignoring the effect of PARTITION BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes