我正尝试在查询的每一行上更新表中的一列。我的代码是:
UPDATE CUSTOM_ISR_ASSET_DETAILS SET COUNTSYSTEMASSETS = ( Select Count(PARENT_ID) as COUNTSYSTEMASSETS
from PM_ENTITY
inner join
(SELECT
pm_entity.PM_ENTITY_ID,
response_text.response_text
FROM pm_entity
INNER JOIN response_text
ON pm_entity.pm_entity_id=response_text.parent_id
AND response_text.question_id = '000ZLIJCA0003MI82Z000UWLUTG000000P4V') TBL_StandardRollup
on PM_ENTITY.PM_ENTITY_ID = TBL_StandardRollup.PM_ENTITY_ID
WHERE (TBL_StandardRollup.response_text = 'Standard')
group by PARENT_ID);
我尝试做的是用每个父id的计数来更新每一行,但很明显,这返回了>1行,所以更新失败。所以,我不能用这段sql代码来做这件事。
如何才能使用父ids的计数更新每一行?
发布于 2017-02-25 02:58:12
请尝试使用merge语句。这将类似于:
merge into CUSTOM_ISR_ASSET_DETAILS c
using (/*YOUR SUB_QUERY*/) d
on (d.response_text = c./*what column 'standard' come from*/)
when matched then update set COUNTSYSTEMASSETS = d.COUNTSYSTEMASSETS;
我不能定义什么是连接条件。我猜'standard'
的值是从哪里来的。
https://stackoverflow.com/questions/42445414
复制相似问题