CS FundamentalsVery hardAmazon/Flipkart SQL round · GATE CS

Table Score(name, pts) rows: ('a', 90), ('b', 85), ('c', 90), ('d', 70), ('e', 85), ('f', 60). What does this query return?

Table Score(name, pts) rows: ('a', 90), ('b', 85), ('c', 90), ('d', 70), ('e', 85), ('f', 60). What does this query return?
SELECT RANK() OVER (ORDER BY pts DESC),
       DENSE_RANK() OVER (ORDER BY pts DESC)
FROM Score
WHERE name = 'f';
  1. A. 1, 1
  2. B. 6, 5
  3. C. 5, 3
  4. D. 6, 4

Correct answer: A. 1, 1

The window is computed after WHERE, so only f's row is left and both functions give 1. Without the WHERE, f would be RANK 6, DENSE_RANK 4.

More DBMS and SQL questions

Exams that ask this topic