CS FundamentalsModerateProduct-company interview pattern

Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen', 'Delhi', 700), (5, 'Dia', NULL, 200), (6, 'Ben', 'Delhi', 700). What does this query return?

Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen', 'Delhi', 700), (5, 'Dia', NULL, 200), (6, 'Ben', 'Delhi', 700). What does this query return?
SELECT AVG(amount) FROM Orders;
  1. A. 400
  2. B. 416.67
  3. C. 480
  4. D. NULL

Correct answer: C. 480

AVG ignores NULLs: (500 + 300 + 700 + 200 + 700) / 5 = 2400 / 5 = 480. 400 divides by all 6 rows, as if the NULL were 0.

More DBMS and SQL questions

Exams that ask this topic