Hello,
I've spent way too long trying to figure out how to group products with their categories and THEN show a subtotal at the end and show it all in a report.
I have a list of products sold in a date range. They need to be grouped by category, grouped by product and show the total items sold for each product and then show a subtotal at the end of each category. There are three tables: orders, products and items. Here's my query and it's working except I don't know how to do the subtotal thing. I know it's involved, but any ideas or changes to my design would be highly appreciated!
SELECT SUM(oitems.numitems * oitems.unitprice) AS ordertotal,
orders.odate, products.catalogid, products.cname,
SUM(oitems.numitems) AS totalitems, orders.orderid,
products.ccategory, categories.catextra,
categories.catdescription,
oitems.numitems * products.cost AS cost
FROM dbo.orders INNER JOIN
dbo.oitems ON
dbo.orders.orderid = dbo.oitems.orderid INNER JOIN
dbo.products ON
dbo.oitems.catalogid = dbo.products.catalogid INNER JOIN
dbo.categories ON
dbo.products.ccategory = dbo.categories.categoryid
WHERE (dbo.orders.oprocessed = 1)
GROUP BY dbo.orders.odate, dbo.products.catalogid,
dbo.products.cname, dbo.orders.orderid,
dbo.products.ccategory, dbo.categories.catextra,
dbo.categories.catdescription,
dbo.oitems.numitems * dbo.products.cost
Thanks very much!
I've spent way too long trying to figure out how to group products with their categories and THEN show a subtotal at the end and show it all in a report.
I have a list of products sold in a date range. They need to be grouped by category, grouped by product and show the total items sold for each product and then show a subtotal at the end of each category. There are three tables: orders, products and items. Here's my query and it's working except I don't know how to do the subtotal thing. I know it's involved, but any ideas or changes to my design would be highly appreciated!
SELECT SUM(oitems.numitems * oitems.unitprice) AS ordertotal,
orders.odate, products.catalogid, products.cname,
SUM(oitems.numitems) AS totalitems, orders.orderid,
products.ccategory, categories.catextra,
categories.catdescription,
oitems.numitems * products.cost AS cost
FROM dbo.orders INNER JOIN
dbo.oitems ON
dbo.orders.orderid = dbo.oitems.orderid INNER JOIN
dbo.products ON
dbo.oitems.catalogid = dbo.products.catalogid INNER JOIN
dbo.categories ON
dbo.products.ccategory = dbo.categories.categoryid
WHERE (dbo.orders.oprocessed = 1)
GROUP BY dbo.orders.odate, dbo.products.catalogid,
dbo.products.cname, dbo.orders.orderid,
dbo.products.ccategory, dbo.categories.catextra,
dbo.categories.catdescription,
dbo.oitems.numitems * dbo.products.cost
Thanks very much!