Today, Lenz was putting together some stats on PlanetMySQL feeds
added since January this year, and asked in an email whether he
should include totals in the stats. I responded yes, and offered
a quick SQL solution to get those numbers out of the database. I
thought it might be useful for others, so here goes...
Rolling sums (or averages) are a way to include a running, or
rolling, aggregate of certain columns in the output of your SQL.
For instance, let's say you want to list order totals, grouped by
product category, but in each row of the final output, you wish
to include the running total of all rows in the output up to and
including the current row. A running sum would allow you to do
such a calculation.
In the specific example that came up today, Lenz had the
following SQL statement which listed the month the feed was …
[Read more]