这条sql怎么写,没有思路啊
sql吧
全部回复
仅看楼主
level 2
id表示位置,连续; NAME为名字
现在要每2个更换位置, 1/2互换;3/4互换;如果最后是单独一个则不动
输出结果为:
IDNAME
1li
2wang
3hu
4chen
5zhao
2019年08月09日 06点08分 1
level 3
-----先加一个id2字段
-----将id数据写入id2
update 表 set id = id2;
-----根据id2重写id
update 表 set id = id2+1 where id2%2<>0 and id2<>max(id2);
update 表 set id = id2-1 where id2%2=0 and id2<>max(id2);
2019年08月21日 17点08分 3
level 3
create table #tmp (
id int identity(1,1),
nameCN varchar(10))
insert into #tmp
select 'a' union all
select 'b' union all
select 'c' union all
select 'd' union all
select 'e' union all
select 'f' union all
select 'g' union all
select 'h' union all
select 'i'
update t1
set t1.nameCN=case when t1.id%2>0 then isnull(t2.nameCN,t1.nameCN) else t3.nameCN end
from #tmp t1
left join #tmp t2 on t1.id+1=t2.id
left join #tmp t3 on t1.id-1=t3.id
2019年09月09日 09点09分 4
1