how to do total with out using any group
Hi
I am having two tables like this in one table names with roll no and in another table roll no and marks now i need to calculate 10 members marks total total 30 students are there after 10 members i want total
like this:
1
2
3
4
5
6
7
8
9
10
total
11
12
13
.
.
20
total
July 19th, 2012 5:20am
create table #t (id int)
insert into #t values (0)
insert into #t values (10)
insert into #t values (20)
insert into #t values (30)
insert into #t values (40)
insert into #t values (50)
insert into #t values (60)
insert into #t values (70)
insert into #t values (80)
insert into #t values (90)
insert into #t values (1)
insert into #t values (2)
insert into #t values (3)
insert into #t values (4)
insert into #t values (5)
insert into #t values (6)
insert into #t values (7)
insert into #t values (8)
insert into #t values (9)
with cte
as
(
select *,case when id%10=0 then 1 else 0 end groupid from #t
) ,cte1
as
(
select groupid ,sum(id) total from cte group by groupid
) select id from (select groupid,id from cte
union all
select groupid,total from cte1 ) as der order by groupid descBest Regards,Uri Dimant SQL Server MVP,http://sqlblog.com/blogs/uri_dimant/
Blog : MS SQL Development and Optimization
Blog : Large
scale of database and cleansing
Free Windows Admin Tool Kit Click here and download it now
July 19th, 2012 5:40am
Hi bharathi.y,
Is this SSRS question ?? If yes then can you eloborate more on what you are trying to achieve ? Because in SSRS this is the most basic thing you can achieve using Groups.
Thanks, Khilit
http://www.bigator.com
July 19th, 2012 11:46am