Practice Activity - Creating a rolling total over the last 3 months in SQL Server

Описание к видео Practice Activity - Creating a rolling total over the last 3 months in SQL Server

If you are in March, how can you total January, February and March's figures in SQL Server?
My SQL Server Udemy courses are:
70-461, 70-761 Querying Microsoft SQL Server with T-SQL: https://rebrand.ly/querying-microsoft...
98-364: Database Fundamentals (Microsoft SQL Server): https://rebrand.ly/database-fundamentals
70-462 SQL Server Database Administration (DBA): https://rebrand.ly/sql-server-dba
Microsoft SQL Server Reporting Services (SSRS): https://rebrand.ly/sql-server-ssrs
SQL Server Integration Services (SSIS): https://rebrand.ly/sql-server-ssis
SQL Server Analysis Services (SSAS): https://rebrand.ly/sql-server-ssas-mdx
Microsoft Power Pivot (Excel) and SSAS (Tabular DAX model): https://rebrand.ly/microsoft-powerpiv...
----
You can create a running total using partition functions. However, what if you only wanted the running total to be over the last 3 months?
There are many ways of doing this. In this video, we will look at using a correlated query, and using a self-join.
We will also be looking at the DATEDIFF and DATEFROMPARTS functions.
Here is the code that we will be using to create the tables, if you want to use this as a Practice Activity:
DROP TABLE IF EXISTS Invoices;
CREATE TABLE Invoices
(InvoiceDate date,
InvoiceAmount int);
INSERT INTO Invoices
VALUES
('2022-12-01', 1), ('2023-02-01', 1), ('2023-02-15', 1),
('2023-03-01', 3), ('2023-04-01', 2), ('2023-04-15', 2),
('2023-05-01', 5), ('2023-06-01', 3), ('2023-06-15', 3), ('2023-08-01', 8);

Комментарии

Информация по комментариям в разработке