Management & CommerceHardBusiness analytics · SQL · MBA placement

orders(oid, cust, amount): (1, A, 100), (2, A, 200), (3, A, 600), (4, B, 300), (5, B, 500), (6, C, 900). How many rows does this return? SELECT oid FROM orders o WHERE amount > (SELECT AVG(amount) FROM orders WHERE cust = o.cust);

  1. A. 3
  2. B. 1
  3. C. 4
  4. D. 2

Correct answer: D. 2

The subquery is correlated, so each order is compared with its own customer's average: A's average is 300 (order 3 qualifies), B's 400 (order 5), and C's 900 (900 is not greater than itself). Two rows. Comparing with the overall average of about 433 would give 3.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic