Загрузка страницы

SQL Tutorial - How to Calculate Rolling Totals

Another video brought to you by BeardedDev, bringing you tutorials on Business Intelligence, SQL Programming and Data Analysis.

You can now support me on patreon - https://www.patreon.com/beardeddev

In this SQL Tutorial we discuss how to calculate rolling totals using window functions. We go through examples using the over clause and taking advantage of changing our window/frames by using rows preceding and current row. There is also a bonus in this tutorial where we show an example of how to use current row and rows following.

If you would like to see more video tutorials on window functions there is a playlist available on my channel.

SQL:
SELECT
*
, SUM(SalesAmount) OVER(ORDER BY [Date] ROWS BETWEEN 9 PRECEDING AND CURRENT ROW) AS Total
, SUM(SalesAmount) OVER(ORDER BY [Date] ROWS BETWEEN CURRENT ROW AND 9 FOLLOWING) AS Forward
FROM #TempSales
ORDER BY [Date]

Please feel free to comment below.

Видео SQL Tutorial - How to Calculate Rolling Totals канала BeardedDev
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
14 ноября 2018 г. 4:46:22
00:10:06
Яндекс.Метрика