🌱 Calculate Moving Average in PostgreSQL

Source
SELECT a.order_date,a.sale,
       AVG(a.sale)
       OVER(ORDER BY a.order_date ROWS BETWEEN 4 PRECEDING AND CURRENT ROW)
       AS avg_sales
       FROM sales a ;
Made by Brandon . If you find this project useful you can donate.