Management & CommerceHardBusiness analyst · SQL test

cust(id, name) has rows (1, Asha), (2, Ravi), (3, Meena), (4, Kiran), (5, Dev). ord(oid, cid, amt, dt) has rows (1, 1, 500, 2 Jan), (2, 1, 300, 5 Jan), (3, 3, 200, 3 Jan), (4, 3, 200, 3 Jan), (5, 5, 900, 4 Jan), (6, 1, 100, 9 Jan). What does SELECT cid, dt, amt, COUNT(*) FROM ord GROUP BY cid, dt, amt HAVING COUNT(*) > 1 return?

  1. A. No rows, because the oids differ
  2. B. Two rows: one for cid 1 and one for cid 3
  3. C. One row: cid 3, 3 Jan, 200, count 2
  4. D. One row: cid 1, count 3

Correct answer: C. One row: cid 3, 3 Jan, 200, count 2

Grouping by customer, date and amount puts orders 3 and 4 together (same cid, date and amount) – a likely duplicate. Customer 1's three orders differ in date and amount, so each forms its own group with count 1. oid is not in the GROUP BY, so it does not separate them.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic