Wednesday 9 October 2013

01The SalesOrderDetail and SalesOrderHeader tables store the details of the sales orders. You have created a backup of the SalesOrderDetail and SalesOrderHeader tables in the SalesOrderDetail_Backup and SalesOrderHeader_Backup tables. To generate a report displaying the sales order ID and the total amount of all the products purchased against an order, you are using the following query: SELECT sd.SalesOrderID, SUM(LineTotal) AS [Total Amount] FROM Sales.SalesOrderDetail_Backup sd JOIN Sales.SalesOrderHeader_Backup sh ON sd.SalesOrderID = sh.SalesOrderID GROUP BY sd.SalesOrderID The table contains a large amount of data. Suggest a solution to optimize the execution of this query.


1 comment: