Hi everybody,
I need to select sales info from 2 tables and group it by year.
tables:
salesdetails
>>sale_id, qty_ordered, qty_shipped, date_shipped, sale_prod_id
products
>>prod_id, price
I need to show for EACH Year:
total qty of products ordered,
total qty of products shipped,
total value of products ordered (price* qty_ordered)
Here is my thing but it gives me a wrong results - much higher qty & total:
SELECT datepart(yy,date_shipped) as sales_year, sum(qty_ordered) as total_orders, sum(qty_shipped) as total_shipped, sum(price*qty_ordered) as total_sales
FROM salesdetails sd, products p
WHERE p.prod_id_id=sd.sale_prod_id
GROUP BY datepart(yy,date_shipped)
What I'm doing wrong?
I need to select sales info from 2 tables and group it by year.
tables:
salesdetails
>>sale_id, qty_ordered, qty_shipped, date_shipped, sale_prod_id
products
>>prod_id, price
I need to show for EACH Year:
total qty of products ordered,
total qty of products shipped,
total value of products ordered (price* qty_ordered)
Here is my thing but it gives me a wrong results - much higher qty & total:
SELECT datepart(yy,date_shipped) as sales_year, sum(qty_ordered) as total_orders, sum(qty_shipped) as total_shipped, sum(price*qty_ordered) as total_sales
FROM salesdetails sd, products p
WHERE p.prod_id_id=sd.sale_prod_id
GROUP BY datepart(yy,date_shipped)
What I'm doing wrong?