日期:2014-05-17 浏览次数:20641 次
select 1 [round],-1 result
into #t
union all select 2,-1
union all select 3,-1
union all select 4,1
union all select 5,-1
union all select 6,-1
union all select 7,1
union all select 8,1
select result,count(1) [count]
from
(
select *,ROW_NUMBER() over(partition by result order by round) rn
from #t
) t
group by [round]-rn,result;
create table kt
(round int, result int)
insert into kt
select 1, -1 union all
select 2, -1 union all
select 3, -1 union all
select 4, 1 union all
select 5, -1 union all
select 6, -1 union all
select 7, 1 union all
select 8, 1
select a.result,
(select count(1) from kt c
where c.round<=a.round and c.result=a.result
and not exists(select 1 from kt d
where d.round between c.round and a.round
and d.result<>c.result)) 'count'