Reputation: 95
Goal. To make a query that displays Product Name(Products), Product Type(ProductTypes), and total number of sales of each product(Sales)
I am having real difficulty figuring out how I am meant to do this. I am trying to do a UNION and a few other things but cannot get it to work.
I can get the total number of sales by using this SELECT ProductID, count(*) as NumSales from Sales group by ProductID
but really struggling to do the rest and format it correctly. Any help would be appreciated.
EDIT:
Select Products.ProductName, ProductTypes.ProductType
From Products
INNER JOIN ProductTypes ON Products.ProductTypeID=ProductTypes.ProductTypeID
I have this to display this right now, just need to join the sales count somehow.
Upvotes: 0
Views: 197
Reputation: 528
try:
select prod.ProductName, ptyp.ProductType, count(SaleID) count_sale
from Products prod
join ProductTypes ptyp on ( ptyp.ProductTypeID= prod.ProductTypeID)
join Sales sal on ( sal.ProductID = prod.ProductID)
group by prod.ProductName, ptyp.ProductType
Upvotes: 1