我有此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)