Войти
  • 6753Просмотров
  • 3 года назадОпубликованоSQL Server 101

Practice Activity: Divide dates into 3 months (quarters) periods

How can we group together rows into 3 month periods? My SQL Server Udemy courses are: 70-461, 70-761 Querying Microsoft SQL Server with T-SQL: 98-364: Database Fundamentals (Microsoft SQL Server): 70-462 SQL Server Database Administration (DBA): Microsoft SQL Server Reporting Services (SSRS): SQL Server Integration Services (SSIS): SQL Server Analysis Services (SSAS): Microsoft Power Pivot (Excel) and SSAS (Tabular DAX model): ---- How can we group January, February, March together, and then April, May and June together? What if we don't want to group 3 months together, but 4 months, 6 months, or 2 months? If you want to do this as a Practice Activity, then please used this code to start with. 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), ('2023-09-01', 1), ('2023-10-01', 2), ('2023-11-01', 3), ('2023-12-01', 4), ('2024-01-01', 1); SELECT InvoiceDate, InvoiceAmount FROM Invoices