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;
- A. 300
- B. 280
- C. 310
- 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
- Consider the schedule W1(B), W2(A), R2(A), W1(A), R3(A), W3(B). Which statement is correct?
- Classify the schedule W2(A), W1(B), W1(A), R1(B), C1, W2(B), R2(B), C2 (Ci = commit of Ti) by the strongest property it satisfies.
- A query runs WHERE a = 7 AND b > 100 ORDER BY b. Which single B+ tree index serves it best?
- R(A, B, C, D) has functional dependencies AD → C, A → D, AC → D, D → A. What is the highest normal form R satisfies?
- R occupies 600 blocks and S occupies 400 blocks. Ignoring the cost of writing the result, what is the cost of a hash join (partitioning…
- In a B+ tree every internal node can have at most 101 children and every leaf can hold at most 80 keys. With exactly 3 levels (root at…