Sql Pivot表我怎么做的?

时间:2012-11-27 12:10:47

标签: sql group-by pivot cube rollup

您好我想问一下我的工作

select * from 
  (Select m.Brand,u.Color,Count(Unit)as [Total unit] 
   from Brands m 
   inner join Products u on m.BrandID=u.ProductID 
   Group by m.Brand ,u.Color 
   with cube
   )as Pvt 
   PIVOT ( Sum([total unit]) 
   For Color IN ( [Black],[White],[Gray],[Silver],[Orange],[Dark Blue] ) 
   )AS Pivot_Table

我想显示品牌总数和总颜色,但此代码只计算每种颜色并计算每个品牌的每种颜色

我如何获得总品牌和总颜色?

0 个答案:

没有答案