Your cart is currently empty!
ChatGPT Prompt for Calculating Moving Average in SQL
A Moving Average (MA) is a widely used statistical and mathematical technique that helps smooth out short-term fluctuations and highlight longer-term trends in data. It is commonly applied in time series analysis, economics, finance, signal processing, and many other fields.
A MA is calculated by taking the mean of a fixed number of data points within a “sliding window” that moves through the dataset. As new data becomes available, the window shifts forward, dropping the oldest value and including the newest one.
For example, with a 3-point moving average:
- Original data: [2, 4, 6, 8, 10]
- Moving average: [4, 6, 8]

ChatGPT Prompt for Calculating MA in SQL
I want you to act as a data scientist and write SQL code for me. I have a table with two columns
[Insert column names]
. I would like to calculate a running average for[which value]
. What is the SQL code that works for PostgreSQL 14?
You can also use the search function to find the best prompts for ChatGPT.