MySQL更新单表加入

时间:2013-05-10 21:40:02

标签: mysql

我在表“REVIEW”中有一个值需要根据表中具有相同REFERENCE_NUMBER,特定REVIEW_TYPE和REVIEW_STATUS为“ABSTAIN”的其他记录将REVIEW_STATUS从“UNDER_REVIEW”更改为“Abstain”。我在SQL Fiddle

中设置了一个示例

http://sqlfiddle.com/#!2/8227f/1

我能够在表中查询记录,但是我很难获得更新查询。

-- run   
UPDATE TABLE REVIEW AS REV1  
LEFT JOIN REVIEW AS REV2 
ON (REV1.REFERENCE_NUMBER=REV2.REFERENCE_NUMBER)
SET REV1.REVIEW_STATUS='ABSTAIN' 
WHERE 
REV1.REVIEW_TYPE ='QOC' 
AND 
REV1.REVIEW_STATUS='UNDER_REVIEW'
AND 
REV2.REVIEW_TYPE ='MED_NEC'
AND (REV2.REVIEW_STATUS ='ABSTAIN' )
;  

非常感谢您的帮助!谢谢!

2 个答案:

答案 0 :(得分:2)

更改

UPDATE TABLE REVIEW AS REV1 
...

UPDATE REVIEW AS REV1 
...

更新了 SQLFiddle

答案 1 :(得分:0)

这是单词TABLE

UPDATE  REVIEW AS REV1  
LEFT JOIN REVIEW AS REV2 
ON (REV1.REFERENCE_NUMBER=REV2.REFERENCE_NUMBER)
SET REV1.REVIEW_STATUS='ABSTAIN' 
WHERE 
REV1.REVIEW_TYPE ='QOC' 
AND 
REV1.REVIEW_STATUS='UNDER_REVIEW'
AND 
REV2.REVIEW_TYPE ='MED_NEC'
AND (REV2.REVIEW_STATUS ='ABSTAIN' )
;