Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 5th, 2006, 01:39 AM
Registered User
 
Join Date: Oct 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Assistance with Rollup and Cube

My assignment question is (using the Pubs database):
Create another query but instead of the compute use the Rollup, and then use the CUBE. How are these different from the COMPUTE? Explain your answer.

What I have done is:
SELECT type, AVG (price)
FROM titles
GROUP BY type WITH ROLLUP

SELECT type, AVG (price)
FROM titles
GROUP BY type WITH CUBE

I don’t think I did this correctly tho because my results didn’t appear to change.

Did I use the Rollup and/or Cube incorrectly?


 
Old November 5th, 2006, 05:37 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Jinn,

Take a look at SQL Server's Books Online. There's lots of information about ROLLUP and CUBE in the index under "CUBE operator" and "ROLLUP operator".

The examples in these topics should be enough to explain the difference and help you out.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old November 5th, 2006, 10:18 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Quote:
quote:Originally posted by Jinn
 My assignment question is (using the Pubs database):
Create another query but instead of the compute use the Rollup, and then use the CUBE. How are these different from the COMPUTE? Explain your answer.

What I have done is:
SELECT type, AVG (price)
FROM titles
GROUP BY type WITH ROLLUP

SELECT type, AVG (price)
FROM titles
GROUP BY type WITH CUBE

I don’t think I did this correctly tho because my results didn’t appear to change.

Did I use the Rollup and/or Cube incorrectly?
With only a single column in a GROUP BY, Rollup and Cube will show the same thing... try these queries, instead...

SELECT City,State,COUNT(*)
FROM STORES
GROUP BY City,State WITH ROLLUP

SELECT City,State,COUNT(*)
FROM STORES
GROUP BY City,State WITH CUBE

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select errors on Count() w/ rollup for a datagrid cJeffreywang ASP.NET 2.0 Basics 0 April 7th, 2008 07:14 PM
how to add perspectives in a Cube through C# mayafantasy ADO.NET 0 February 14th, 2007 09:33 AM
Rollup Question kjward SQL Server 2000 0 February 7th, 2007 11:51 AM
Accessing cube in VB ashwinik VB Components 1 January 25th, 2005 06:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.