Reputation: 25830
I want to do a query like this:
UPDATE State
LEFT JOIN Actions ON Actions.id = State.id
SET duration = FLOOR(AVG(duration)) WHERE type = 'started' GROUP BY Actions.id
How would I do this? (It says the group by is an error)
Upvotes: 0
Views: 32
Reputation: 204766
UPDATE State
INNER JOIN
(
select id, FLOOR(AVG(duration)) as avg
from Actions
WHERE type = 'started'
group by id
) tmp ON tmp.id = State.id
SET duration = tmp.avg
Upvotes: 2
Reputation: 157
Short answer is:
UPDATE State LEFT JOIN Actions ON Actions.id = State.id SET duration = FLOOR(AVG(duration)) WHERE Actions.id IN ( select id from Actions where Actions.id = state.id and type = 'started' GROUP BY Actions.id )
Probably not quite syntactically correct.
Upvotes: 0