Bird
0
0

What will this query return?

medium📝 query result Q5 of 15
SQL - Window Functions Fundamentals
What will this query return?
SELECT id, amount, ROW_NUMBER() OVER (PARTITION BY region ORDER BY amount DESC) AS rank FROM sales;
ARandom row numbers without order
BTotal count of rows per region
CSum of amounts per region
DA rank of rows within each region ordered by amount descending
Step-by-Step Solution
Solution:
  1. Step 1: Understand ROW_NUMBER() OVER with PARTITION and ORDER BY

    ROW_NUMBER() assigns a unique rank number to each row within each region ordered by amount descending.
  2. Step 2: Interpret the rank column

    Rows with highest amount in each region get rank 1, next rank 2, and so on.
  3. Final Answer:

    A rank of rows within each region ordered by amount descending -> Option D
  4. Quick Check:

    ROW_NUMBER() ranks rows per partition [OK]
Quick Trick: ROW_NUMBER() ranks rows within partitions [OK]
Common Mistakes:
  • Confusing ROW_NUMBER() with COUNT()
  • Ignoring ORDER BY inside OVER()
  • Thinking ranks are global, not per partition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes