I might be overlooking something very obvious but I cannot get my multiple UPDATE
statement to run. What I want to achieve is to SELECT
an AVG()
value from a table and UPDATE
a column based on these values in another table.
I followed the following solution, but could not make it run:
my solution:
UPDATE
teams
SET
teams.overall_rank = q.rank_avg
FROM
(
SELECT
team_id as t_id,
AVG(rank) as rank_avg
FROM
team_list
WHERE
rank NOT IN (0, -1)
GROUP BY
team_id
ORDER BY
rank_avg
) q
WHERE
q.t_id = teams.team_id
The error message:
You have an error in your SQL syntax; it seems the error is around: 'FROM ( SELECT team_id as t_id, AVG(rank) as rank_avg FR' at line 5
I am using MySQL. What am I missing here?