🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.WHERE RANK() = 2
  2. B.WHERE rn <= 2, where rn = ROW_NUMBER() OVER (PARTITION BY dept_id ORDER BY salary DESC)
  3. C.HAVING COUNT(*) = 2
  4. 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 →