Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rollup Query Help

0 views
Skip to first unread message

Frank Py

unread,
Dec 26, 2003, 6:49:45 PM12/26/03
to

I found this great rollup query example that uses grouping and sub
totals. Would it be possible to expand on this and include a group
within a group and subtotal each group? For example, parent product then
child product? Help appreciated. Thanks.
Frank

SQL:
SELECT
CASE
WHEN (Grouping(CategoryName)=1) THEN 'MainTotal'
ELSE CategoryName
END AS CategoryName,

CASE
WHEN (Grouping(ProductName)=1) THEN 'SubTotal'
ELSE Productname
END AS ProductName,

Sum(UnitPrice) as UnitPrice,
Sum(UnitsinStock) as UnitsInStock

FROM Products
INNER JOIN Categories On
Products.CategoryID = Categories.CategoryID
GROUP BY CategoryName, ProductName WITH ROLLUP


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

David Portas

unread,
Dec 27, 2003, 2:16:46 PM12/27/03
to
CUBE/ROLLUP will subtotal by whatever columns you specify, so presumably you
need to change the GROUP BY to something like:

...
GROUP BY categoryname, subcategoryname, productname WITH ROLLUP

If this doesn't answer your question please post DDL for this table, post
INSERT statements to generate a few rows of sample data and show your
required result.

--
David Portas
------------
Please reply only to the newsgroup
--


0 new messages