1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. In SUM(x) OVER (ORDER BY d), the default window frame uses…

Added 30 Nov -0001

In SUM(x) OVER (ORDER BY d), the default window frame uses RANGE. What practical difference does that make compared with an explicit ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW?

  1. RANGE requires a PARTITION BY clause, whereas ROWS can be used over the whole table without one
  2. ROWS ignores the ORDER BY, whereas RANGE sorts the partition before summing
  3. Rows that tie on d are all included in the same running total under RANGE, while ROWS admits them one at a time Correct answer
  4. RANGE includes only the current row, whereas ROWS accumulates every preceding row in the partition

Correct answer

C. Rows that tie on d are all included in the same running total under RANGE, while ROWS admits them one at a time

17 views

MCQSEXAM

Explanation

A window frame defines which rows an analytic function sees; with ORDER BY and no explicit frame, the default is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW. RANGE treats peers, rows with equal d, as one unit, so every tied row receives the same cumulative total, whereas ROWS CURRENT ROW advances row by row and gives tied rows different totals. Use ROWS when you need a strict row count and RANGE when ties should share a value, and remember that an explicit frame overrides the default.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? 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