急求:sql难题之把name字段补充完整 高手赐教
答案:2 悬赏:30 手机版
解决时间 2021-04-07 12:34
- 提问者网友:美人性情
- 2021-04-07 03:16
急求:sql难题之把name字段补充完整 高手赐教
最佳答案
- 五星知识达人网友:污到你湿
- 2021-04-07 03:41
update table
set name = (select name from table a where a.id = table.id - 1)
where isnull(name,'') = ''
你看看这个可以不,如果不可以就需要循环处理
大致如下:
declare @begin int = 1
declare @end int
declare @id int
select @end = count(1) from table
where isnull(name,'') = ''
select row_number() over(order by id) new_id,id,name into #table from table
while(@begin <= @end)
begin
select @id = id from #table
where new_id = @begin
update table
set name = (select name from table a where a.id = @id - 1)
where id = @id
set @begin += 1
end
纯手打,如有错误或看不明白的,请追问
set name = (select name from table a where a.id = table.id - 1)
where isnull(name,'') = ''
你看看这个可以不,如果不可以就需要循环处理
大致如下:
declare @begin int = 1
declare @end int
declare @id int
select @end = count(1) from table
where isnull(name,'') = ''
select row_number() over(order by id) new_id,id,name into #table from table
while(@begin <= @end)
begin
select @id = id from #table
where new_id = @begin
update table
set name = (select name from table a where a.id = @id - 1)
where id = @id
set @begin += 1
end
纯手打,如有错误或看不明白的,请追问
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯