sybase cursor and report

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值