🙏 We need your help! SQLtest.online has no ads and lives only on donations. Even a small amount helps. Donate now →
SQL code copied to buffer
Task 16:

How Long Were Products on Sale

SQL Server 2022
Some products are no longer sold: their SellEndDate in the Product table is filled in. List every distinct sale period of these products.
Output the columns sell_start and sell_end (the dates without the time), days_on_sale and months_on_sale (the difference between the two dates in days and in months, as SQL Server counts it), sorted by sell_start, then by sell_end.
Expected result Columns: 4 · Rows: 3
sell_start sell_end days_on_sale months_on_sale

Write your query below and click "Check it!". Tables are described in the right pane.

Tutorial

By checking a query, you agree that it is stored without your account details and may be included in anonymized datasets, including for AI training. Learn more

The query result will appear here. Ctrl+Enter - Run query