我有这个 sql 查询,这是错误的。我想更新wins表中的字段“prevmonth”,但只更新字段“month_wins”的最大值的记录。
UPDATE wins
SET prevmonth_top=1
WHERE month_wins = (SELECT MAX(month_wins) FROM wins)
但是我该怎么做呢?
试试这个技巧,
UPDATE wins
SET prevmonth_top=1
ORDER BY month_wins DESC
LIMIT 1
或类似的东西,
UPDATE IGNORE giveaways
SET winner = 1
WHERE month_wins = (select maxID from (SELECT MAX(ID) maxID FROM giveaways) as t)
运行以下查询,它可能会有所帮助:
UPDATE wins
SET prevmonth_top=1 WHERE month_wins =
(
SELECT month_wins FROM (SELECT MAX(month_wins) FROM wins) AS month_wins
)