CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ

Table Emp(eid, name, mgr, dept, sal) rows: (1, 'Aru', NULL, 'D1', 90), (2, 'Bin', 1, 'D1', 60), (3, 'Cy', 1, 'D2', 70), (4, 'Dev', 2, 'D1', 60), (5, 'Eli', 2, 'D2', 40), (6, 'Fay', 3, NULL, 75), (7, 'Gus', 4, 'D1', 30). mgr refers to eid. What does this query return? SELECT sal FROM Emp e WHERE 2 = (SELECT COUNT(DISTINCT sal) FROM Emp x WHERE x.sal > e.sal);

  1. A. 75
  2. B. 60
  3. C. 90
  4. D. 70

Correct answer: D. 70

It keeps a salary with exactly 2 distinct higher salaries, i.e. the 3rd highest distinct salary. Distinct salaries descending are 90, 75, 70, 60, 40, 30, so the answer is 70.

More DBMS and SQL questions

Exams that ask this topic