Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**SQL**: SELECT user_id, date, clicks, AVG(clicks) OVER (PARTITION BY user_id ORDER BY date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS ma_7d FROM clicks. **Spark**: Window.partitionBy('user_id').orderBy('date').rowsBetween(-6, 0). **Why ROWS**: ROWS 6 PRECEDING = 7 rows...
Pro-Move: 'For sparse data we use RANGE INTERVAL—handles missing days; ROWS fails when dates skip.' Red Flag: ROWS 7 PRECEDING—that is 8 rows; 7-day = 6 PRECEDING.
SQL: SELECT user_id, date, clicks, AVG(clicks) OVER (PARTITION BY user_id ORDER BY date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS ma_7d FROM clicks. Spark: Window.partitionBy('user_id').orderBy('date').rowsBetween(-6, 0). Why ROWS: ROWS 6 PRECEDING = 7 rows (current + 6). Use RANGE for gaps. Best practice: Handle NULLs; ensure date continuity.
Pro-Move: 'For sparse data we use RANGE INTERVAL—handles missing days; ROWS fails when dates skip.' Red Flag: ROWS 7 PRECEDING—that is 8 rows; 7-day = 6 PRECEDING.
According to DataEngPrep.tech, this is one of the most frequently asked General/Other interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.