4
我有一個查詢問題更新查詢
UPDATE Table_1 SET Col1='Y' WHERE ROWID IN (
select ROWID from (
SELECT BUS_ID,
row_number() over (partition by BUS_ID order by BUS_ID) dupe_count,
rowid
from Table_1
WHERE col2 <> 1
AND col3 <> 1
order by dbms_random.value
) ft
where ft.dupe_count = 1
AND ROWNUM <= 1000
);
只更新1000臺TABLE_1行。
但如果我寫
UPDATE Table_1 SET Col1='Y' WHERE ROWID IN (
select ROWID from (
SELECT BUS_ID,
row_number() over (partition by BUS_ID order by BUS_ID) dupe_count,
rowid
from Table_1
WHERE col2 <> 1
AND col3 <> 1
order by dbms_random.value
) ft
where ft.dupe_count = 1
and Table_1.BUS_ID = ft.BUS_ID
AND ROWNUM <= 1000
);
它更新表中的所有行,不論RoWNUM <= 1000
即如果我添加
Table_1.BUS_ID = ft.BUS_ID
則更新滿足col2<> 1 AND col3<> 1 and ft.dupe_count=1
所有行。 該表具有以下結構:
BUS_ID | col1 | col2 | col3
1 | | 0 | 0
2 | | 0 | 0
1 | | 0 | 0
3 | | 1 | 1.
任何想法,爲什麼它happening.Please幫助。
感謝Rob van Wijk。 –