G
gzbxmcx
Unregistered / Unconfirmed
GUEST, unregistred user!
我有两张表 TEMP_DB01_DBB01,a2 现在a1表在有1000条记录,两表中的关键字段都是:QKDM,CWDM,我通过关键字段把a2中的数据查询到以后更新到a1中,并且a1中需要更新的记录数等于a2中所查到的记录并且都是多条记录,请问这个Sql 如何写?注意!数据库ORACLE。
以下是我写的,不过不正确。
UPDATE TEMP_DB01_DBB01 SET (QHSXS,YHSXS,RGBCNLBZ,BDRCYSP, LJKFCL,LJKCCL,
LJKFQCL) = (SELECT B.QHSXS,B.YHSXS,B.RGBCNLBZ, DECODE(B.BDRCYSP,0,0
,B.BDRCYSP) AS BDRCYSP,0,0,0 FROM (SELECT QKDM,
QHSXS,YHSXS,RGBCNLBZ,BDRCYSP, LJKFCL,LJKCCL,LJKFQCL,CWDM FROM
TEMP_DB01_DBB02 WHERE NY='200211' AND CWDM<>'0000000000') B)
WHERE (TEMP_DB01_DBB01.QKDM IN (
SELECT DISTINCT QKDM FROM TEMP_DB01_DBB02
WHERE NY='200211' AND CWDM<>'0000000000' ))
以下是我写的,不过不正确。
UPDATE TEMP_DB01_DBB01 SET (QHSXS,YHSXS,RGBCNLBZ,BDRCYSP, LJKFCL,LJKCCL,
LJKFQCL) = (SELECT B.QHSXS,B.YHSXS,B.RGBCNLBZ, DECODE(B.BDRCYSP,0,0
,B.BDRCYSP) AS BDRCYSP,0,0,0 FROM (SELECT QKDM,
QHSXS,YHSXS,RGBCNLBZ,BDRCYSP, LJKFCL,LJKCCL,LJKFQCL,CWDM FROM
TEMP_DB01_DBB02 WHERE NY='200211' AND CWDM<>'0000000000') B)
WHERE (TEMP_DB01_DBB01.QKDM IN (
SELECT DISTINCT QKDM FROM TEMP_DB01_DBB02
WHERE NY='200211' AND CWDM<>'0000000000' ))