Sunday 6 October 2013

03. Write a query to display the sales order IDs and the order detail IDs along with the total value of those orders that have a total value greater than the average of the total value for the order ID.

select salesOrderDetailID,salesOrderID,LineTotal from sales.salesOrderdetail s1
where s1.lineTotal > (select AVG(s2.Linetotal) from
sales.salesOrderDetail s2
where s1.SalesOrderID=s2.salesOrderID)

No comments:

Post a Comment