SIMULATION -
You create a table named Products.Sales by running the following Transact-SQL statement:
You add the following data to the table.
You are developing a report to display monthly sales data.
You need to create a Transact-SQL query to meet the following requirements:
✑ Retrieve a column for the year followed by a column for each month from January through December.
✑ Include the total sales amount for each month.
Aggregate columns by year, month, and then amount.
Construct the query using the following guidelines:
✑ Use the MONTH keyword as the interval when using the DATANAME function.
✑ Do not modify the provided IN clause.
✑ Do not surround object names with square brackets.
✑ Do not use implicit joins.
✑ Do not use the DATEPART function.
Part of the correct Transact-SQL has been provided in the answer area below. Enter the code in the answer area that resolves the problem and meets the stated goals or requirements. You can add code within the code that has been provided as well as below it.
1. SELECT * FROM
2. (SELECT YEAR(SalesData)) AS Year, DATENAME (MONTH, SalesDate) AS Month, SalesAmount AS Amount
3.
4. ) AS MonthlySalesData
5.
6. FOR Month IN (January, February, March, April, May, June, July, August, September, October, November, December))
AS MonthNamePivot -
Tazul
Highly Voted 5 years, 7 months agorjile
4 years, 10 months agoVermonster
4 years, 4 months agoDieter
Highly Voted 5 years, 8 months agoAshleyLiang
5 years, 8 months agoM4x
5 years, 8 months agoAndy7622
4 years, 4 months agoeduardogtc
Most Recent 4 years, 7 months agoBarbedx
5 years, 2 months agoxd1
5 years agomoehijawe
5 years, 4 months agomoehijawe
5 years, 4 months ago