主账号处理

drop table A
create table A(id int identity(1,1) not null primary key,acc varchar(100),flag int default 0,iszhu char(1) default 0)
insert A(acc)
select '101 000550 8091 111'
union all
select '101 000550 8092 121'
union all
select '101 000553 8093 111'
union all
select '101 000554 8091 111'
union all
select '101 000444 8023 101'
union all
select '101 000444 8043 101'
union all
select '101 000443 8071 101'
union all
select '101 000550 8091 111'
union all
select '101 000550 8093 111'

 

with cte1 as(
select distinct substring(acc,5,7) as number from a
),cte2 as(
select row_number() over(order by number) as id,number   from cte1
)
update A set flag=cte2.id from A,cte2 where substring(acc,5,7)=number


declare @flag int
set @flag=1
while @flag<=(select max(flag) from A)
begin
with cte3 as(
select id,min(acc) as zhanghao from a where flag=@flag and substring(acc,12,4) in('8091','8092','8093','8094','8095','8096','8097','8098','8099') group by id
)
update A set iszhu=1 where id in(select top 1 id from cte3)
set @flag=@flag+1
end

select * from A

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值