如果不重复行字段,请设置字段

时间:2012-01-22 16:45:01

标签: mysql

我想在coins表格中为每个具有唯一100的行设置accounts字段PASSWORD

这可能在MySQL吗?

2 个答案:

答案 0 :(得分:1)

UPDATE accounts a JOIN
( SELECT PASSWORD, COUNT(*) as cnt FROM accounts 
  GROUP BY PASSWORD
  HAVING cnt < 2 ) singles
ON a.PASSWORD = singles.PASSWORD
SET a.coins = 100

答案 1 :(得分:1)

我认为这样可行:

UPDATE accounts
SET coins = 100
WHERE userid IN (
    SELECT * FROM (
        SELECT userid
        FROM accounts AS a
        GROUP BY passwd
        HAVING COUNT(passwd) = 1
        ) AS a
    )
;