select 1 as seq, a.* into SelCommentaryList_jason from SelCommentaryList_terry_res1 a
declare cursor_t cursor
for
select sp_name,run_time,distance,counts from SelCommentaryList_jason order by run_time
go
declare @tmp int
declare @seq int
declare @sp_name varchar(200)
declare @run_time datetime
declare @distance int
declare @counts int
set @seq = 1
set @tmp=1
open cursor_t
fetch cursor_t into @sp_name,@run_time,@distance,@counts
WHILE @@sqlstatus = 0
begin
update SelCommentaryList_jason set seq = @seq where run_time = @run_time
if @tmp%10 = 0
set @seq = @seq + 1
set @tmp = @tmp + 1
fetch cursor_t into @sp_name,@run_time,@distance,@counts
end
close cursor_t
deallocate cursor cursor_t
select sp_name, sum(c1) c1,sum(c2) c2,sum(c3) c3,sum(c4) c4,sum(c5) c5,sum(c6) c6,sum(c7) c7,sum(c8) c8,sum(c9) c9,sum(c10) c10,sum(c11) c11,min(distance) minTime, max(distance) maxTime,avg(distance) avgTime, avg(counts) counts from
(
select seq,sp_name,run_time,distance,counts,
case when(seq = 1) then distance else 0 end as c1,
case when(seq = 2) then distance else 0 end as c2,
case when(seq = 3) then distance else 0 end as c3,
case when(seq = 4) then distance else 0 end as c4,
case when(seq = 5) then distance else 0 end as c5,
case when(seq = 6) then distance else 0 end as c6,
case when(seq = 7) then distance else 0 end as c7,
case when(seq = 8) then distance else 0 end as c8,
case when(seq = 9) then distance else 0 end as c9,
case when(seq = 10) then distance else 0 end as c10,
case when(seq = 11) then distance else 0 end as c11
from SelCommentaryList_jason
) b
group by sp_name
declare cursor_t cursor
for
select sp_name,run_time,distance,counts from SelCommentaryList_jason order by run_time
go
declare @tmp int
declare @seq int
declare @sp_name varchar(200)
declare @run_time datetime
declare @distance int
declare @counts int
set @seq = 1
set @tmp=1
open cursor_t
fetch cursor_t into @sp_name,@run_time,@distance,@counts
WHILE @@sqlstatus = 0
begin
update SelCommentaryList_jason set seq = @seq where run_time = @run_time
if @tmp%10 = 0
set @seq = @seq + 1
set @tmp = @tmp + 1
fetch cursor_t into @sp_name,@run_time,@distance,@counts
end
close cursor_t
deallocate cursor cursor_t
select sp_name, sum(c1) c1,sum(c2) c2,sum(c3) c3,sum(c4) c4,sum(c5) c5,sum(c6) c6,sum(c7) c7,sum(c8) c8,sum(c9) c9,sum(c10) c10,sum(c11) c11,min(distance) minTime, max(distance) maxTime,avg(distance) avgTime, avg(counts) counts from
(
select seq,sp_name,run_time,distance,counts,
case when(seq = 1) then distance else 0 end as c1,
case when(seq = 2) then distance else 0 end as c2,
case when(seq = 3) then distance else 0 end as c3,
case when(seq = 4) then distance else 0 end as c4,
case when(seq = 5) then distance else 0 end as c5,
case when(seq = 6) then distance else 0 end as c6,
case when(seq = 7) then distance else 0 end as c7,
case when(seq = 8) then distance else 0 end as c8,
case when(seq = 9) then distance else 0 end as c9,
case when(seq = 10) then distance else 0 end as c10,
case when(seq = 11) then distance else 0 end as c11
from SelCommentaryList_jason
) b
group by sp_name