Advertisement
hoangreal

Hoang Chu's Ramp Applied Scientist Intern application

Nov 15th, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.53 KB | Source Code | 0 0
  1. SELECT
  2.     transaction_date,
  3.     rolling_3_day_avg
  4. FROM (
  5.     SELECT
  6.         transaction_date,
  7.         total_amount,
  8.         AVG(total_amount) OVER (
  9.             ORDER BY transaction_date
  10.             ROWS BETWEEN 2 PRECEDING AND CURRENT ROW
  11.         ) AS rolling_3_day_avg
  12.     FROM (
  13.         SELECT
  14.             DATE(transaction_time) AS transaction_date,
  15.             SUM(transaction_amount) AS total_amount
  16.         FROM transactions
  17.         GROUP BY DATE(transaction_time)
  18.     ) dt
  19. ) sub
  20. WHERE transaction_date = '2021-01-31';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement