我想在coins
表格中为每个具有唯一100
的行设置accounts
字段PASSWORD
。
这可能在MySQL吗?
答案 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
)
;