我想一次更新两个表。下面的代码似乎正常工作。但在某些情况下,bidGroups没有条目意味着整个句子都会失败。为了更新第一个,我如何调整它?(watchedItems),并且如果watchedItems.bidGroupID为NULL不要尝试第二部分 ) u3 x, O5 a, x: y' C+ qUPDATE watchedItems,bidGroups SET watchedItems.won=1,bidGroups.bidGroupQty=bidGroups.bidGroupQty-1 WHERE watchedItems.id=2 AND watchedItems.aid=200618152822 AND bidGroups.bidGroupID=watchedItems.bidGroupID AND bidGroups.id=2;我试过,但语法错了。 . Q$ ^% c. z) D2 [# y% OUPDATE watchedItems,bidGroups SET watchedItems.won=1,CASE WHEN watchedItems.bidGroupID IS NOT NULL THEN bidGroups.bidGroupQty=bidGroups.bidGroupQty-1 ELSE ENDWHERE watchedItems.id=2 AND watchedItems.aid=200618152822 AND bidGroups.bidGroupID=watchedItems.bidGroupID AND bidGroups.id=2 2 ! l# n# L) ~6 U7 u8 D 解决方案: 1 [+ L/ C* p) Z1 x
这样试试LEFT JOIN:% i& ^0 \. b# @3 W/ [
UPDATE watchedItems LEFT JOIN bidGroups ON watchedItems.bidGroupID = bidGroups.bidGroupID AND bidGroups.id=2SET watchedItems.won=1,bidGroups.bidGroupQty=bidGroups.bidGroupQty-1 WHERE watchedItems.id=2 AND watchedItems.aid=200618152822;......