UPDATE PlayerLeague l
JOIN PlayerStat s ON l.player_id=s.player_id
SET l.league_id=8
WHERE l.league_id=2
ORDER BY s.score
DESC LIMIT 5
我有错误:
{ [Error: ER_WRONG_USAGE: Incorrect usage of UPDATE and ORDER BY]
code: 'ER_WRONG_USAGE', index: 0 }
这是什么意思?
我试试这个:
UPDATE PlayerLeague l
SET l.league_id=8
WHERE l.player_id IN
(SELECT player_id FROM PlayerStat s
JOIN PlayerLeague l ON s.player_id=l.player_id
WHERE l.league_id=2
ORDER BY s.score
DESC LIMIT 5)
但这也是错误的。
答案 0 :(得分:0)
我找到了解决方案:
UPDATE PlayerLeague l
JOIN (SELECT s.player_id
FROM PlayerStat s
JOIN PlayerLeague l
ON s.player_id=l.player_id
WHERE l.league_id=2
ORDER BY s.score DESC LIMIT 5
) AS temp
ON l.player_id=temp.player_id
SET l.league_id=8
答案 1 :(得分:0)
我不确定您是否打算通过使用LIMIT或检索具有高分的TOP 5 playerID然后使用该playerID更新所有行来限制仅更新几行。
如果是第一种情况,LIMIT应该在JOIN之外。你应该检查正确的语法。但如果是第二种情况,那么这里是查询。
update PlayerLeague pl
JOIN
(
select t1.player_id
from PlayerLeague t1
join PlayerStat t2
on t1.player_id=t2.player_id
and t1.league_id=2
order by t2.score desc
limit 5
)ps
ON pl.player_id=ps.player_id
set pl.league_id=8