CS FundamentalsModerateAmazon/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?
SELECT AVG(pay), AVG(COALESCE(pay, 0)) FROM Staff;
- A. 45, 45
- B. 54, 54
- C. 45, 54
- D. 54, 45
Correct answer: D. 54, 45
AVG ignores the NULL pay: 270/5 = 54. COALESCE turns it into 0, so the second average is 270/6 = 45.
More DBMS and SQL questions
- R(A, B, C, D, E, F) has functional dependencies AE → BC, B → F, E → C, BD → E, F → E. Which of the following is the complete set of…
- R(A, B) = {(a1, b2), (a1, b3), (a2, b1), (a2, b2), (a2, b3), (a3, b1), (a4, b1), (a4, b2), (a4, b3)} and S(B) = {b1, b3}. What is R ÷ S?
- The system crashes after the last record of this log (immediate database modification; <Ti, X> denotes an update with old and new values…
- Table Sale(id, rep, region, amt) rows: (1, 'Ira', 'N', 100), (2, 'Jai', 'S', 250), (3, 'Ira', 'S', NULL), (4, 'Kim', 'N', 300), (5, 'Jai'…
- R(A, B, C, D, E, F) has functional dependencies B → ACDEF. What is the highest normal form R satisfies?
- Which isolation anomaly is still possible at the SQL REPEATABLE READ level (as defined by the SQL standard)?