467,923 Members | 1,331 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,923 developers. It's quick & easy.

Rollup Query Help


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!
Jul 20 '05 #1
  • viewed: 5142
Share:
1 Reply
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
--
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by UNIXNewBie | last post: by
1 post views Thread by js | last post: by
3 posts views Thread by apattin | last post: by
reply views Thread by Ike | last post: by
1 post views Thread by slowpoke115 | last post: by
reply views Thread by Tonkuma | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.