0

我需要生成一个类似这样的 mysql 查询:

更新 TRANSACTION SET 点 = 0 WHERE TransactionID NOT IN(SELECT TransactionID, COUNT(*) FROM trans_products GROUP BY TransactionID WHERE COUNT(*) > 1)

关键是我需要更新在表“trans_products”中存在一次的“事务”表中的事务

任何帮助

4

1 回答 1

0

尝试:

UPDATE
    TRANSACTION
SET
    points = 0
WHERE
   TransactionID IN (
       SELECT 
           TransactionID
       FROM
           trans_products
       GROUP BY
           TransactionID
       HAVING
           COUNT(*) = 1
   )

编辑:根据您需要添加 ProductID 的评论,您不能有WHEREafterHAVING子句。这就是你需要的:

UPDATE
    TRANSACTION
SET
    points = 0
WHERE
   TransactionID IN (
       SELECT 
           TransactionID
       FROM
           trans_products
       WHERE
           ProductID = '192'
       GROUP BY
           TransactionID
       HAVING
           COUNT(*) = 1
   )
于 2012-07-18T15:54:09.953 回答