how to do total with out using any group


hi

i having 2 tables in 1 table names roll no , in table roll no , marks need calculate 10 members marks total total 30 students there after 10 members want total

like this:

1

2

3

4

5

6

7

8

9

10

total

11

12

13

.

.

20

total

create table #t (id int)

insert #t values (0)
insert #t values (10)
insert #t values (20)
insert #t values (30)
insert #t values (40)
insert #t values (50)
insert #t values (60)
insert #t values (70)
insert #t values (80)
insert #t values (90)



insert #t values (1)
insert #t values (2)
insert #t values (3)
insert #t values (4)
insert #t values (5)
insert #t values (6)
insert #t values (7)
insert #t values (8)
insert #t values (9)

cte
as
(
select *,case when id%10=0 1 else 0 end groupid #t
) ,cte1
as
(
 select groupid ,sum(id) total cte group groupid
) select id (select groupid,id cte
  union all
  select groupid,total cte1 ) der order groupid desc

best regards,uri dimant sql server mvp,http://sqlblog.com/blogs/uri_dimant/



SQL Server  >  SQL Server Reporting Services, Power View



Comments

Popular posts from this blog

Motherboard replacement

Cannot create Full Text Search catalog after upgrading to V12 - Database is not fully started up or it is not in an ONLINE state

Remote Desktop App - Error 0x207 or 0x607