日期:2014-05-17 浏览次数:20515 次
create table tb(pid varchar(10),coadcladcon int)
insert into tb
select 'PRAA0370',1 union all
select 'PRAA0370',2 union all
select 'PRAA0370',3 union all
select 'PRAA0370',4 union all
select 'PRAA0370',5 union all
select 'PRAA0370',6 union all
select 'PRAA0371',1 union all
select 'PRAA0371',2 union all
select 'PRAA0371',3 union all
select 'PRAA0371',4 union all
select 'PRAA0371',5 union all
select 'PRAA0371',6 union all
select 'PRAA0371',7
with cte as
(
select no=row_number() over(partition by pid order by getdate()),*,
num=(select count(*) from tb where pid=a.pid)
from tb a
)
select pid,coadcladcon
from (select no1=row_number() over(partition by pid order