我有这个问题:
UPDATE ranking_position
SET position = ranking_position.position - 1
WHERE ( ranking_position.position > 3 )
AND tournament_team_id IN ( SELECT id
FROM tournament_team team
WHERE team.category_id = 38 )
应该"向上移动"在属于第38类的第3个职位之后,每个团队的位置;
发生的事情是,每次运行此查询时,它只更新1行;
如果我使用完全相同的标准执行SELECT查询:
SELECT *
FROM ranking_position
WHERE position > 3
AND tournament_team_id IN ( SELECT id
FROM tournament_team team
WHERE team.category_id = 38 )
我得到了预期的结果(很多行)。
我做错了什么?
谢谢!
答案 0 :(得分:0)
试试这个。
UPDATE ranking_position
SET position = ranking_position.position - 1
WHERE ( ranking_position.position > 3 )
FROM
ranking_position t
INNER JOIN tournament_team team
ON tournament_team_id IN ( SELECT id
FROM tournament_team team
WHERE team.category_id = 38 )