Management & CommerceHardBusiness analyst · SQL test

Table m(store, mon, rev) has S1: month 1 = 100, month 2 = 120, month 3 = 90; S2: month 1 = 200, month 2 = 180. What does rev − LAG(rev) OVER (PARTITION BY store ORDER BY mon) give for S2's month 1 and month 2?

  1. A. plus 110 and minus 20
  2. B. 0 and minus 20
  3. C. NULL and minus 20
  4. D. NULL and 180

Correct answer: C. NULL and minus 20

LAG looks at the previous row within the same partition. S2's first month has no previous S2 row, so LAG is NULL and the difference is NULL – it does not borrow S1's month 3 (90). Month 2 gives 180 − 200 = −20.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic