Bird
0
0

You want to calculate a moving average of sales amounts over the last 3 days including the current day, using sales(date, amount). Which window frame clause correctly achieves this?

hard📝 Application Q8 of 15
PostgreSQL - Window Functions in PostgreSQL
You want to calculate a moving average of sales amounts over the last 3 days including the current day, using sales(date, amount). Which window frame clause correctly achieves this?
ARANGE BETWEEN INTERVAL '3 days' PRECEDING AND CURRENT ROW
BROWS BETWEEN 3 PRECEDING AND CURRENT ROW
CRANGE BETWEEN 3 PRECEDING AND CURRENT ROW
DROWS BETWEEN INTERVAL '3 days' PRECEDING AND CURRENT ROW
Step-by-Step Solution
Solution:
  1. Step 1: Understand requirement

    We want to include all rows within 3 days before current date.
  2. Step 2: Choose correct frame type

    RANGE with INTERVAL '3 days' PRECEDING includes all rows with dates in that range.
  3. Step 3: Validate options

    RANGE BETWEEN INTERVAL '3 days' PRECEDING AND CURRENT ROW uses RANGE with INTERVAL correctly; ROWS counts rows, not days.
  4. Final Answer:

    RANGE BETWEEN INTERVAL '3 days' PRECEDING AND CURRENT ROW -> Option A
  5. Quick Check:

    Use RANGE with INTERVAL for date ranges [OK]
Quick Trick: Use RANGE with INTERVAL for date-based frames [OK]
Common Mistakes:
  • Using ROWS for date ranges
  • Using numeric offsets with RANGE
  • Mixing INTERVAL with ROWS

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes