A running (or cumulative) sum calculation can be useful in warranty scenarios.
/* This selects the total sales in the * 12 most recent months. */ DEFINE Input AS SELECT DimDate_CalendarYear AS "Year", DimDate_MonthNumberOfYear AS "Month", SUM(FactSales_SalesAmount) AS TotalSales GROUP BY "Year", "Month" ORDER BY "Year" DESC, "Month" DESC PAGE(0, 12); RETURN CumulativeSum AS SELECT one."Year" AS "Year", one."Month" AS "Month", SUM(many.TotalSales) AS TotalSales FROM Input one JOIN Input many ON ((one."Year" > many."Year") OR (one."Year" = many."Year" AND one."Month" >= many."Month") ) GROUP BY "Year", "Month" ORDER BY "Year", "Month"
In the example, the words "one" and "many" are statement aliases to clarify the roles in this many-to-one self-join. Looking at the join condition, you can think of this as, for each (one) record, create multiple records based on the (many) values that match the join condition.