日期:2014-05-17 浏览次数:20459 次
create table [a]([djbh] varchar(10),[spid] varchar(10),[shl] int)
insert [a]
select 'bh001' ,'sp001' ,10 union all
select 'bh001' ,'sp002' ,11 union all
select 'bh001' ,'sp003' ,15 union all
select 'bh002' ,'sp001' ,10 union all
select 'bh002' ,'sp002' ,11 union all
select 'bh002' ,'sp003' ,15 union all
select 'bh003' ,'sp001' ,97 union all
select 'bh003' ,'sp003' ,98 union all
select 'bh003' ,'sp004' ,99
select * from a
--处理测试数据
select *,row_number() over(PARTITION BY djbh order by djbh,spid) as rowid into #a from a
select * from #a