Question discussion

What does the following query return?CREATE TABLE s(n TEXT, m INT); INSERT INTO s VALUES ('a',90),('b',90),('c',80),('d',70); SELECT n, RAN…

1577Medium DSSSB TGT Computer Science 0 replies 1 views
0

What does the following query return?

CREATE TABLE s(n TEXT, m INT);
INSERT INTO s VALUES ('a',90),('b',90),('c',80),('d',70);
SELECT n, RANK() OVER (ORDER BY m DESC) AS r,
       DENSE_RANK() OVER (ORDER BY m DESC) AS d FROM s WHERE n = 'c';
  • Ac 1 1
  • Bc 3 2
  • Cc 3 3
  • Dc 2 2
Correct answer: A

Explanation

The WHERE clause is applied before window functions are evaluated, so only the row for c remains and both RANK() and DENSE_RANK() return 1 for it.

Discussion 0

Nobody has replied yet. Start the discussion!