将嵌套sql更新查询转换为联接操作
我想知道如何将查询更改为加入具有相同结果的查询:将嵌套sql更新查询转换为联接操作,sql,oracle,join,nested,Sql,Oracle,Join,Nested,我想知道如何将查询更改为加入具有相同结果的查询: update CDR set CDR_TYPE = 'ON_NET' where anum in (select subscriber from DEGREE where sub_type = 'MTN') and bnum in (select subscriber from DEGREE where sub_
update CDR
set CDR_TYPE = 'ON_NET'
where anum in (select subscriber
from DEGREE
where sub_type = 'MTN')
and bnum in (select subscriber
from DEGREE
where sub_type = 'MTN')
仅供参考:我正在使用ORACLE数据库
致以最诚挚的问候。您可以使用WITH子句来消除重复的子查询
UPDATE
(SELECT cdr_type
FROM cdr c
INNER JOIN degree d
ON c.anum = d.subscriber
AND c.bnum = d.subscriber
WHERE d.sub_type = 'MTN'
) t
SET t.cdr_type = 'ON_NET'
WITH subquery AS (select subscriber
from DEGREE
where sub_type = 'MTN')
UPDATE cdr
SET cdr_type = 'ON_NET'
WHERE anum IN (subquery)
AND bnum IN (subquery);
Sql server、mysql或oracle?实际上,它们在join/update OPERATIONRACLE数据库中有不同的语法。我认为oracle不支持
update
语句中的join
。因此,如何提高查询的性能呢?您可能想看看这个答案=>就像旁观者一样,这是一个非常有趣的查询。介意解释一下子查询是如何工作的吗?它应该更新5200多万条记录,而只更新其中的18k条!