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
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
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
SQL TUTORIAL - GROUP BY, HAVING, Aggregate FunctionsSQL Interview Questions - What is the difference between Rank and Dense RankHow to create an Azure SQL DatabaseT-SQL Tutorial - When is DISTINCT evaluatedSQL Development - Cross JoinsSQL Tutorial - Difference between CTEs and Derived TablesSQL Tutorial - Subqueries (Scalar Valued)SQL for Beginners Part 4 - DISTINCTQlikView Tutorial - Load InlineSQL Interview Questions - FizzBuzz ChallengeSQL TUTORIAL - Add ColumnT-SQL Tutorial - REPLICATESQL Tutorial - How to create a Dynamic Pivot in SQL Part 2SQL Sunday Quiz - Week 1SQL TUTORIAL - CTEs Part 1SQL Sunday Quiz - Week 4SQL Tutorial - Window Functions (Follow Along)How I became an Microsoft Certified Solutions Expert in Data Management and AnalyticsSQL Tutorial - How to drop a column from a tableDifferent Roles Working With DataSQL Tutorial - Views