May 31, 2011 at 6:03 am
Hi All,
I am trying to understand how Rollup works. following query summarize
Use AdventureWorks
select Production.ProductCategory.ProductCategoryID
,GROUPING(Production.ProductCategory.ProductCategoryID)
, Production.Product.ProductSubcategoryID
,GROUPING(Production.Product.ProductSubcategoryID)
, AVG(Listprice) As 'Average'
, MIN(ListPrice) As 'Min'
, MAX(ListPrice) As 'Max'
from Production.Product
join Production.ProductSubcategory
on production.ProductSubcategory.ProductSubcategoryID =
production.Product.ProductSubcategoryID
join Production.ProductCategory
on production.ProductSubcategory.ProductCategoryID =
production.ProductCategory.ProductCategoryID
where ListPrice <> 0
group by (production.ProductCategory.ProductCategoryID), (production.Product.ProductSubcategoryID)
with rollup
having MIN(ListPrice) > 200
produces following result
ProductCategoryID(No column name)ProductSubcategoryID(No column name)AverageMinMax
10101683.365539.993399.99
10201597.45539.993578.27
10301425.2481742.352384.07
10NULL11586.737539.993578.27
20120678.2535249.791364.50
20140780.0436337.221431.50
20160631.4155333.421003.91
My Question is why it doesn't summarize where productCategoryID is 2?
May 31, 2011 at 8:27 am
Comment out HAVING clause and if that doesn't help, comment-out WHERE also.
Please use aliases, e.g:
SELECT mt.Name
from myDatabase.mySchema.MyTable mt -- mt is alias from this long full table name
May 31, 2011 at 8:43 pm
Sorry... didn't read the post correctly and withdrew my post.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply