CS FundamentalsVery hardAmazon/Flipkart SQL round · GATE CS

Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2). What does this query return?

Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2). What does this query return?
UPDATE Staff SET pay = pay + 10
WHERE pay < (SELECT AVG(pay) FROM Staff);
SELECT SUM(pay) FROM Staff;
  1. A. 300
  2. B. 280
  3. C. 310
  4. D. 290

Correct answer: D. 290

The subquery is evaluated against the table before the update: average 54. Only Anu (40) and Esha (35) are below it, so the total rises from 270 to 290. Dev's NULL + 10 stays NULL.

More DBMS and SQL questions

Exams that ask this topic