← Quiz: Window Functions: all 10 questions
Quiz: Window Functions · Question 9 of 10
You need the top 2 earners in every department. Which filter goes in the outer query?
You need the top 2 earners in every department. Which filter goes in the outer query?
- A.WHERE RANK() = 2
- B.WHERE rn <= 2, where rn = ROW_NUMBER() OVER (PARTITION BY dept_id ORDER BY salary DESC)
- C.HAVING COUNT(*) = 2
- D.LIMIT 2
Answer & explanation
Correct answer: WHERE rn <= 2, where rn = ROW_NUMBER() OVER (PARTITION BY dept_id ORDER BY salary DESC)
Number the rows inside each department, then keep the first two. LIMIT 2 would keep only two rows in total.
Can you get the rest right without peeking?
Take the timed Quiz: Window Functions quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →