如何组合这两个查询?
选择mysql查询:
SELECT avg(b.averageRating)
FROM review a INNER
JOIN review b ON b.institudeId=a.institudeId
WHERE a.reviewId='3';
更新mysql查询:
update table institutions
set averageRatings=avg(b.averageRating)
where id=a.institudeId;
答案 0 :(得分:6)
您可以尝试此查询:
UPDATE institutions SET institutions.overallRatings = (
SELECT avg(b.averageRating)
FROM review a
INNER JOIN review b ON b.institudeId=a.institudeId WHERE a.reviewId='3'
)
WHERE institutions.id = (
SELECT institudeId FROM review WHERE reviewId='3'
)