Management & CommerceVery hardBusiness analyst · SQL test

orders(oid, cust, amount) has rows (1, A, 100), (2, A, 200), (3, B, 300). items(oid, sku) lists the products in each order: order 1 has 2 items, order 2 has 1, order 3 has 3. An analyst runs SELECT SUM(o.amount) FROM orders o JOIN items i ON o.oid = i.oid to get total revenue. What does it return?

  1. A. 600
  2. B. 1300
  3. C. 1,400
  4. D. 6

Correct answer: B. 1300

The join repeats each order once per item: 100 × 2 + 200 × 1 + 300 × 3 = 1300. True revenue is 600. Joining to a 'many' table before aggregating a 'one'-side column inflates totals – aggregate first or sum from orders alone.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic