473,657 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Categ oryName)=1) THEN 'MainTotal'
ELSE CategoryName
END AS CategoryName,

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

Sum(UnitPrice) as UnitPrice,
Sum(UnitsinStoc k) as UnitsInStock

FROM Products
INNER JOIN Categories On
Products.Catego ryID = Categories.Cate goryID
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
1 5370
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5312
by: UNIXNewBie | last post by:
Am looking at an Oracle SQL reference book. They have the following SQL for ROLLUP which works SELECT 0.YEAR, TO_CHAR(TO_DATE(O.MONTH, 'MM'), 'Month') MONTH, R.NAME REGION, SUM(O.TOT_SALES) FROM ORDERS O, REGION R
1
2550
by: c.le_roq | last post by:
Hello, Using rollup I want to count the number of rows of a table called Table1 which is LEFT JOINED with a table called Table2. The problem is that we can have more than 1 rows in Table2 that matched 1 row in Table1. As a consequence the count of rows in table1 is bigger than the real number of rows contained in table1. For example:
1
1555
by: js | last post by:
I have a SQL Server 2003 stored procedure that uses "select ... group by ... with rollup" syntax. The total of columns from the query varies from 3 to 4. The query returns several rollup generated null column rows. In an ASP.Net form, I have a datagrid.DataSource bound to the query result from a DataReader. The grid has AutoGenerateColumns = false. I manually add 1st and 2nd columns of the datagrid. The query result is bound to...
3
4833
by: apattin | last post by:
Hi all, I need some expert advice on a ROLLUP fine point. summary_table table has 4 columns: file_id primary_site morphology primary
0
3825
by: Ike | last post by:
When I use "With rollup," I am getting totals on columns which are numeric, however, non-numeric columns are copying down to the rollup column (i.e. the last column's non-numeric columns are being duplicated on the rollup column). For example. if I order by date with rollup and, I am also outputting emplyee, and some numeric value , at the rollup row, the totals appear, that date, of course, properly appears, but the employee name from...
1
3469
by: vanandwiz | last post by:
Please find the code below. SELECT COMPANY.NAME, COUNT(ITEM.ID) FROM ITEM, COMPANY WHERE ITEM.COMPANYID = COMPANY.ID GROUP BY ROLLUP(COMPANY.NAME)
1
2491
by: slowpoke115 | last post by:
I want to total everything in the 'spare slots' column of my database, heres the query generating the spare slots column, can someone please help me? I've wrote on this forum before with no reply... in fact I've wrote on lots of forums with the same question and nobodys come close to giving me an answer :( Someone suggested using the rollup function to tally total everything in the spare slots column, but I cant get this to work. SELECT...
3
4273
by: traceable1 | last post by:
I installed the SQL Server 2005 SP2 update 2 rollup on my 64-bit server and the performance has tanked! I installed rollup 3 on some of them, but that did not seem to help. I thought it was just a linked server performance issue, but my optimization started running today on one of the "update 2" instances and so far it's been running about 10 hours longer than it normally
0
2513
by: Tonkuma | last post by:
Download a Summary of the DB2 for i 6.1 (i5/OS V6R1) Enhancements (109 KB): http://www-03.ibm.com/systems/i/software/db2/pdf/db2_v6r1_enhancements.pdf On January 29, 2008, IBM announced a new version of i5/OS. Version 6 Release 1 (V6R1) of i5/OS includes an updated version of DB2 for i5/ OS, which is built into the operating system. In addition, several new products are available for DB2 for i5/OS in a similar timeframe as V6R1.
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.