CREATE TABLE transactions (
  id INT PRIMARY KEY,
  created_at DATETIME NOT NULL,
  amount DECIMAL(10, 2) NOT NULL
);

INSERT INTO transactions (id, created_at, amount) VALUES
(1, '2024-01-01 10:00:00', 100.00),
(2, '2024-01-01 11:00:00', 150.00),
(3, '2024-01-01 12:00:00', 50.00),
(4, '2024-01-01 13:00:00', 200.00);

SELECT
  id,
  created_at,
  amount,
  AVG(amount) OVER (ORDER BY created_at ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS running_avg
FROM
  transactions
ORDER BY
  created_at;


https://sqlfiddle.com/mysql/online-compiler?id=72900364-1f06-4a40-ae1a-b411bb8393d8

    All notes