Posted by: NEPAL_SACH22 May 3, 2010
Login in to Rate this Post:
0
?
Try this out the_hareeb.
select
ID,name,Category, SUM(Children)as Total_Childrenfrom
myBaseTablegroup
by ID,name,Category with rollup
here is another one that gives you exactly what you wanted:
Select
Id, Name, Category=Case when ig=1 then 'SUBTOTAL' else Category end, ChildrenFROM
(
SelectId
, Name, Category, Children=Sum(Children),ig
=Grouping(Id), ng=Grouping(Name), cg=Grouping(Category) From myBaseTable Group by rollup (category,Id,Name))
GroupedWhere
ng = ig and cg <> 1Thanks!
Last edited: 03-May-10 10:19 PM