update tbl t set a='1' where not exists(select 1 from tbl b where b.rowid>t.rowid and b.a=t.a and ...);
对哦我怎么没想到 update tbl set a='1' where a='2' and b='2' and ... and rownum=1;
update t_weather set weather = 'changed' where rownum < 2
rowid 可以实现了 rownum 报错 请再给个rownum 的完整例子
ROWID 是可以的,ROWNUM不行
重复的取一条记录update ta a set a.name='b' where not exists(select 1 from ta b where a.id=b.id and a.rowid<b.rowid)
union一下也行. update ta a set a.name='b' where not exists(select 1 from ta b where a.id=b.id and a.rowid <b.rowid)
SQL> select * from t1; ID NAME ---------- -------------------- 1 xx 1 xx --假设你想更新name为xx的数据 SQL> update t1 2 set name='gg' 3 where name='xx' 4 and rownum=1;1 row updated.SQL> select * from t1; ID NAME ---------- -------------------- 1 gg 1 xx
where 条件怎么写法
update tbl set a='1' where a='2' and b='2' and ... and rownum=1;
set weather = 'changed'
where rownum < 2
rownum 报错 请再给个rownum 的完整例子
where not exists(select 1 from ta b where a.id=b.id and a.rowid<b.rowid)
update ta a set a.name='b'
where not exists(select 1 from ta b where a.id=b.id and a.rowid <b.rowid)
---------- --------------------
1 xx
1 xx
--假设你想更新name为xx的数据
SQL> update t1
2 set name='gg'
3 where name='xx'
4 and rownum=1;1 row updated.SQL> select * from t1; ID NAME
---------- --------------------
1 gg
1 xx
使用子查询也不可以啊