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). For customer 1, what running totals does SUM(amt) OVER (PARTITION BY cid ORDER BY dt) give for orders 1, 2 and 6, in date order?

  1. A. 500, 800, 900
  2. B. 500, 300, 100
  3. C. 900, 900, 900
  4. D. 100, 400, 900

Correct answer: A. 500, 800, 900

Partitioned by customer and ordered by date, the window sums all earlier rows plus the current one: 500; 500 + 300 = 800; 800 + 100 = 900. Without ORDER BY the window would be the whole partition (900 on every row).

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic