1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. What does LAG(sales, 1, 0) OVER (PARTITION BY store ORDER…

Added 30 Nov -0001

What does LAG(sales, 1, 0) OVER (PARTITION BY store ORDER BY month) return?

  1. The store's average sales, with 0 substituted wherever the partition is empty or has one row
  2. The next month's sales within the same store, with 0 substituted for the last row of each partition
  3. The running total of sales within each store, starting at 0 at the very first row of every partition here
  4. The previous month's sales within the same store, with 0 substituted for the first row of each partition Correct answer

Correct answer

D. The previous month's sales within the same store, with 0 substituted for the first row of each partition

14 views

MCQSEXAM

Explanation

LAG looks backwards within the window frame, one row at a time here, and the third argument supplies a default instead of NULL for the first row of each partition. PARTITION BY restarts the window per store, so months never cross between stores. LEAD is the forward-looking counterpart, and SUM over an ordered frame gives the running total.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More SQL for Data Analysis MCQs

Practise all SQL for Data Analysis MCQs

Similar MCQs