2017-08-25 110 views
0

我正在嘗試更新活動字段並根據有多少產品已發送給客戶進行設置。但它沒有按預期工作。我有一些recordShipped比totalIssues大但isActive沒有被設置爲false。MySQL與計數的比較

UPDATE xatm.subscriptions a, 
     (SELECT idSubscription, COUNT(idProduct) issueShipped 
     FROM xatm.subscriptionshipments 
     group by idSubscription) b 
SET a.isActive = (a.totalIssues > b.issueShipped) 
WHERE a.idsubscriptions = b.idSubscription 
AND a.isComp = 0 AND a.isReoccurring = 0; 
+0

我的感覺是,你的查詢是否正確。你能否包含一些數據來說明你遇到的問題? –

回答

1

其實,我覺得你當前的查詢應該工作,但在任何情況下,你可以嘗試將是一個更新的替代聯接:

UPDATE xatm.subscriptions a 
INNER JOIN 
(
    SELECT idSubscription, COUNT(idProduct) issueShipped 
    FROM xatm.subscriptionshipments 
    GROUP BY idSubscription 
) b 
    ON a.idsubscriptions = b.idSubscription 
SET a.isActive = (a.totalIssues > b.issueShipped) 
WHERE 
    a.isComp = 0 AND 
    a.isReoccurring = 0;