Advanced
Complex SQL Window Functions
Solve a complex data retrieval problem using advanced window functions and CTEs.
📝 Contenido del prompt
Given a dataset of sales transactions including transaction_id, user_id, amount, and timestamp, write a PostgreSQL query to calculate the 3-day moving average of sales per user alongside the user's total sales amount up to but not including the current transaction date. Use Common Table Expressions (CTEs) for clarity and window functions for frame calculation. Provide an explanation of how the frame clause affects the calculation.