上一行的改成下一行,那么是'a'改成'b'了还是'b'改成'a'啊? update table1 a set zd2= (select zd2 from table1 b where zd1=a.zd1 and zd3=a.zd3-1 ) where exists( select 1 from table1 b where zd1=a.zd1 and zd3=a.zd3-1 )
update table1 a set zd2= (select max(zd2)keep(dense_rank last order by rowid) from table1 where zd1=a.zd1) where rowid<>( select max(rowid) from table1 where zd1=a.zd1)
update table a set zd2 = (select zd2 from table where zd2 <> 0 and zd1 = a.zd1) where zd1 = 0这是正确答案,我要结贴了,谢谢你的回答。
update tabel set zd2='b' where zd2='a'你的具体条件是什么啊?
字段:zd1,zd2,zd3
值:zd1,zd2 ,zd3
1 a 1
1 b 2
2 c 3
2 d 4
3 c 5
3 d 6
...将zd1相同的行中上一行的zd2的值改成下一行
字段:zd1,zd2,zd3
值:zd1,zd2 ,zd3
1 a 1
1 b 2
2 c 3
2 d 4
3 e 5
3 f 6
... 将zd1相同的行中上一行的zd2的值改成下一行
通过一个for循环,对每一个上一行的值进行判断
如果两个zd1相同
那么把上一行的zd2的值改成下一行就可以了
你前面说把b改为a
可这里的意思又是把a改为b
zd1 zd2 zd3
bh1 0 dw1
bh1 100 dw1
bh2 0 dw2
bh2 200 dw2
bh3 0 dw3
bh3 300 dw3
...
将zd1 = 'bh1'的zd2的值都改为100
将zd1 = 'bh2'的zd2的值都改为200
将zd1 = 'bh3'的zd2的值都改为300
依次类推用一个update语句能实现吗?
这样明白了吗?
update table1 a set zd2=
(select zd2 from table1 b where zd1=a.zd1
and zd3=a.zd3-1
)
where exists(
select 1 from table1 b where zd1=a.zd1
and zd3=a.zd3-1
)
(select max(zd2)keep(dense_rank last order by rowid)
from table1 where zd1=a.zd1)
where rowid<>(
select max(rowid) from table1 where zd1=a.zd1)