Comments - Window Frames

7 years, 11 months ago Rick James

After a lot of guessing, I see that MariaDB supports things like these:

SELECT
       AVG(x) OVER(ORDER BY date RANGE BETWEEN 4 PRECEDING AND CURRENT ROW)  AS MovingAvg,
       SUM(x) OVER(ORDER BY date RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS CumulativeTotal
FROM t;

That assumes that `x` is some numeric thing you are interested in, and the table needs to be sorted by `date` for computing a "Moving Average" and a "Cumulative Total".

 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.