CS FundamentalsHardAmazon · Microsoft MCQ pattern

Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2), (4, 'John', 'Sales', 40000, 1), (5, 'Kiran', 'IT', 90000, 2), (6, 'Dev', NULL, 45000, 4), (7, 'Lata', 'Sales', NULL, 4). What is the value of running for Ravi (id 2)?

Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2), (4, 'John', 'Sales', 40000, 1), (5, 'Kiran', 'IT', 90000, 2), (6, 'Dev', NULL, 45000, 4), (7, 'Lata', 'Sales', NULL, 4). What is the value of running for Ravi (id 2)?
SELECT id, salary,
       SUM(salary) OVER (ORDER BY salary) AS running
FROM Emp
WHERE salary IS NOT NULL;
  1. A. 205000
  2. B. 275000
  3. C. 365000
  4. D. 135000

Correct answer: B. 275000

With ORDER BY and no frame clause, the default frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, which includes all peers with the same salary. 40000 + 45000 + 50000 + 70000 + 70000 = 275000 for both Ravi and Meena. 205000 assumes a row-by-row (ROWS) frame.

More DBMS and SQL questions

Exams that ask this topic