Hint: RANK() skips numbers after ties, DENSE_RANK() does not [OK]
Common Mistakes:
Assuming ranks after ties are consecutive
Confusing RANK() with DENSE_RANK()
Misordering rows by score
4. Identify the error in this query:
SELECT name, DENSE_RANK(score) OVER (ORDER BY score DESC) FROM players;
medium
A. DENSE_RANK() should not have a column inside the parentheses.
B. DENSE_RANK() cannot be used without PARTITION BY clause.
C. ORDER BY clause is missing in the OVER() clause.
D. The query is correct and will run without errors.
Solution
Step 1: Check DENSE_RANK() syntax
DENSE_RANK() does not take any arguments inside parentheses; it is called as DENSE_RANK() OVER (...).
Step 2: Identify the error in the query
The query incorrectly uses DENSE_RANK(score), which causes a syntax error.
Final Answer:
DENSE_RANK() should not have a column inside the parentheses. -> Option A
Quick Check:
DENSE_RANK() has empty parentheses [OK]
Hint: Window functions have empty parentheses, column goes in ORDER BY [OK]
Common Mistakes:
Putting column inside DENSE_RANK()
Thinking PARTITION BY is mandatory
Omitting OVER() clause
5. You want to assign ranks to employees based on their sales, but you want no gaps in ranking numbers even if some employees have the same sales. Which function should you use and why?
Options: A) ROW_NUMBER() because it gives unique numbers. B) RANK() because it skips ranks after ties. C) DENSE_RANK() because it assigns ranks without gaps after ties. D) COUNT() because it counts rows.
hard
A. DENSE_RANK() because it assigns ranks without gaps after ties.
B. RANK() because it skips ranks after ties.
C. ROW_NUMBER() because it gives unique numbers.
D. COUNT() because it counts rows.
Solution
Step 1: Understand ranking requirements
The requirement is to assign ranks with no gaps even if employees tie in sales.
Step 2: Match functions to behavior
ROW_NUMBER() gives unique numbers, ignoring ties. RANK() skips ranks after ties causing gaps. DENSE_RANK() assigns ranks without gaps after ties.
Step 3: Choose correct function
DENSE_RANK() fits the requirement perfectly.
Final Answer:
DENSE_RANK() because it assigns ranks without gaps after ties. -> Option A
Quick Check:
DENSE_RANK() = no gaps in ranks [OK]
Hint: Use DENSE_RANK() to avoid gaps in ranking numbers [OK]
Common Mistakes:
Choosing RANK() and expecting no gaps
Using ROW_NUMBER() which ignores ties
Confusing COUNT() with ranking functions
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.