gpt4 book ai didi

sql - 更新查询的问题

转载 作者:行者123 更新时间:2023-12-05 00:10:52 25 4
gpt4 key购买 nike

我有一个查询

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
);

仅更新表 Table_1 中的 1000 行。

但如果我写
 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.

知道为什么会这样。请帮忙。

最佳答案

尼拉吉,

为每个表评估一个普通的子查询。为每一行评估相关子查询。并且您在第二个更新语句中创建了与行 Table_1.BUS_ID = ft.BUS_ID 相关的子查询。 .如果它对每一行进行评估,那么它将始终满足 ROWNUM <= 1000谓词。

问候,
抢。

关于sql - 更新查询的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7305330/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com