I am writing a SQL query using the AdventureWorks 2014 database.
I want to show Which orders contain more than two products? Show order number, order value, and number of products that the order contains.
I tried to write statement by itself (see below), but I'd like to be able to solve the relation :
select SalesOrderID , ProductID , LineTotal
from Sales.SalesOrderDetail
order by SalesOrderID
SELECT SalesOrderID,
COUNT(ProductID) as total_products,
SUM(LineTotal) as total_invoice
FROM SalesOrderDetail s
GROUP BY SalesOrderID
HAVING COUNT(ProductID) > 2
ORDER BY s.SalesOrderID