日期:2014-05-17 浏览次数:20679 次
with tb(id,col)as(
select 1,'A' union all
select 2,'B' union all
select 3,'C' union all
select 4,'A' union all
select 5,'A' union all
select 6,'A' union all
select 7,'C' union all
select 8,'B' union all
select 9,'B' union all
select 10,'B' union all
select 11,'D' union all
select 12,'A' union all
select 13,'A' union all
select 14,'A' union all
select 15,'A' union all
select 16,'A' union all
select 17,'C')
,tc as(
select col,number=id-row_number() over(partition by col order by id) from tb
)
select col,count(number) from tc
group by col,number
having count(number)>1