Skip to content
Advertisement

SQL query – count the number of items sold

I am trying to solve the following question:

How many items with ListPrice more than $1000 have been sold?

The query gives me the results per Product ID, but I would need the total number of item sold.

I can’t figure out how to do that.

This is my query:

select count(pro.ProductID), pro.Name, pro.ListPrice
from Product as pro
    join  SalesOrderDetail as sod
        on (pro.ProductID = sod.ProductID)
where pro.ListPrice > 1000
group by pro.ProductID, pro.Name, pro.ListPrice
having count(*)

Advertisement

Answer

Depending on the details you provided, your query should be like below :

select count(pro.ProductID)
from Product as pro
    join  SalesOrderDetail as sod
        on pro.ProductID = sod.ProductID
where pro.ListPrice > 1000
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement