﻿ AdventureWorks: Find total cost of each order exceeds 100000

# AdventureWorks Database: Find total cost of each order exceeds 100000

## SQL Query - AdventureWorks: Exercise-27 with Solution

27. From the following table write a query in SQL to retrieve the total cost of each salesorderID that exceeds 100000. Return SalesOrderID, total cost.

Sample table: Sales.SalesOrderDetail

Click to view Full table

Sample Solution:

``````SELECT SalesOrderID, SUM(orderqty*unitprice) AS OrderIDCost
FROM Sales.SalesOrderDetail
GROUP BY SalesOrderID
HAVING SUM(orderqty*unitprice) > 100000.00
ORDER BY SalesOrderID;
``````

Sample Output:

```salesorderid|orderidcost|
------------+-----------+
43875|122744.1667|
43884|116248.4897|
44518|127099.9957|
44528|108783.5872|
44530|104960.0101|
44795|104588.7130|
46066|100378.9078|
46067|101857.2130|
46607|121037.4456|
46616|153432.0611|
46643|110830.3608|
46645|101373.1246|
46660|119415.1966|
46981|149533.7021|
47018|107991.0123|
47027|105375.2251|
47355|130185.6757|
...
```

## Practice Online

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿