Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**SQL**: SELECT trans_date, SUM(amount) AS daily, AVG(SUM(amount)) OVER (ORDER BY trans_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS ma_7d FROM transactions GROUP BY trans_date. **Logic**: Inner SUM for daily total; outer AVG over 7 rows. **Spark**: Group by date, then...
SQL: SELECT trans_date, SUM(amount) AS daily, AVG(SUM(amount)) OVER (ORDER BY trans_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS ma_7d FROM transactions GROUP BY trans_date. Logic: Inner SUM for daily total; outer AVG over 7 rows. Spark: Group by date, then window. Best practice: Handle sparse dates; use ROWS for dense.
Pro-Move: 'We use ROWS—transaction dates are dense; RANGE would add complexity for no benefit.' Red Flag: AVG(amount) instead of AVG(SUM(amount))—wrong granularity.
According to DataEngPrep.tech, this is one of the most frequently asked General/Other interview questions, reported at 2 companies. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.