Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Can You Compute?


Can You Compute?

Author
Message
David.Poole
David.Poole
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3696 Visits: 3120
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/dpoole/canyoucomput

LinkedIn Profile

Newbie on www.simple-talk.com
Duncan Sutcliffe
Duncan Sutcliffe
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 56

Thanks!


kenwallacedesign
kenwallacedesign
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 59

Wow, what a thorough explaination! I was tring to explain these concepts to some colleagues over lunch the other day, and your article beats the snot out of my back-of-napkin diagrams!

Thanks!





Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45215 Visits: 39926

Very nice. The graphics you took the time to do the "Alice's Restaurant" thing to really make this a very clear article on what Rollups and Cubes actually do. The graphics clearly demonstrate why you might want to use the Grouping function of a Rollup or Cube.

There's lot's of folks who have no idea what a "subtree cost" is, how to determine it, or what unit of measurement it is. Also, although very obvious from the graphics, simple example Selects for the isolation of subtotals and grandtotals would be very helpful for newbies. A very brief explanation of these two things would have made this a "six star" article.

Outstanding article overall! Thanks for sharing it with us.



--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Antares686
Antares686
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: Moderators
Points: 8426 Visits: 780
You really did do a nice job on this article. Very complete description and nice use of visualizations to send home.



Ian Yates
Ian Yates
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1056 Visits: 445
Excellent article. I had heard of the terms before and had "one day" planned to read up on them thinking they sounded complicated. You made it sound easy - and as it turns out, it really is

THANKS



gonzalomedina
gonzalomedina
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 3

I liked it very much. I would like to see more articles like this on the near future. My only "negative" comment is I was reading the article and "copy and paste" the source code and it has a lot typos, here is the code will run:

SELECT
Cust.country ,
Cat.CategoryName ,
Count(*) AS ProductsBought
FROM dbo.Customers AS Cust
INNER JOIN dbo.Orders AS Ord
ON Cust.CustomerId = Ord.CustomerId
INNER JOIN dbo.[Order Details] AS OrdDet
ON Ord.OrderId = OrdDet.OrderId
INNER JOIN dbo.Products AS Prod
ON OrdDet.ProductId = Prod.ProductId
INNER JOIN dbo.Categories AS Cat
ON Prod.CategoryId = Cat.CategoryId
GROUP BY
Cust.Country ,
Cat.CategoryName
WITH ROLLUP;

SELECT Cust.country ,
Cat.CategoryName ,
Count(*) AS ProductsBought
FROM dbo.Customers AS Cust
INNER JOIN dbo.Orders AS Ord
ON Cust.CustomerId = Ord.CustomerId
INNER JOIN dbo.[Order Details] AS OrdDet
ON Ord.OrderId = OrdDet.OrderId
INNER JOIN dbo.Products AS Prod
ON OrdDet.ProductId = Prod.ProductId
INNER JOIN dbo.Categories AS Cat
ON Prod.CategoryId = Cat.CategoryId
GROUP BY
Cust.Country ,
Cat.CategoryName
order by Cust.country;

GROUP BY clause.
SELECT
Cust.country ,
Cat.CategoryName ,
Count(*) AS ProductsBought,
GROUPING(Cust.country) AS SubtotalForCountries,
GROUPING(Cat.CategoryName) AS SubtotalForCategories
FROM dbo.Customers AS Cust
INNER JOIN dbo.Orders AS Ord
ON Cust.CustomerId = Ord.CustomerId
INNER JOIN dbo.[Order Details] AS OrdDet
ON Ord.OrderId = OrdDet.OrderId
INNER JOIN dbo.Products AS Prod
ON OrdDet.ProductId = Prod.ProductId
INNER JOIN dbo.Categories AS Cat
ON Prod.CategoryId = Cat.CategoryId
GROUP BY
Cust.Country ,
Cat.CategoryName
WITH CUBE ;

SELECT
Prod.ProductId ,
Prod.ProductName ,
Cat.CategoryName ,
Prod.UnitsInStock * Prod.UnitPrice AS StockValue
FROM dbo.Products AS Prod
INNER JOIN dbo.Categories AS Cat
ON Prod.CategoryId = Cat.CategoryId
ORDER BY
Cat.CategoryName
COMPUTE SUM(Prod.UnitsInStock * Prod.UnitPrice);

SELECT
Prod.ProductId ,
Prod.ProductName ,
Cat.CategoryName ,
Prod.UnitsInStock * Prod.UnitPrice AS StockValue
FROM dbo.Products AS Prod
INNER JOIN dbo.Categories AS Cat
ON Prod.CategoryId = Cat.CategoryId
ORDER BY
Cat.CategoryName
COMPUTE SUM(Prod.UnitsInStock * Prod.UnitPrice)
BY Cat.CategoryName;

SELECT
Prod.ProductId ,
Prod.ProductName ,
Cat.CategoryName ,
Prod.UnitsInStock * Prod.UnitPrice AS StockValue
FROM dbo.Products AS Prod
INNER JOIN dbo.Categories AS Cat
ON Prod.CategoryId = Cat.CategoryId
ORDER BY Cat.CategoryName
COMPUTE SUM(Prod.UnitsInStock * Prod.UnitPrice)
BY Cat.CategoryName
COMPUTE SUM(Prod.UnitsInStock * Prod.UnitPrice);

One more time.... Great article.





Al Pagcaliwangan
Al Pagcaliwangan
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 1

A very good explaination!




Kindest Regards,

Al Pagcaliwangan B.S. ECE, B.S.EE
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search