Php 在mysql中单次查询更新并选择内部连接
如何组合这两个查询 选择mysql查询:Php 在mysql中单次查询更新并选择内部连接,php,mysql,Php,Mysql,如何组合这两个查询 选择mysql查询: SELECT avg(b.averageRating) FROM review a INNER JOIN review b ON b.institudeId=a.institudeId WHERE a.reviewId='3'; update table institutions set averageRatings=avg(b.averageRating) where id=a.institudeId; 更新mysql查询: SELECT
SELECT avg(b.averageRating)
FROM review a INNER
JOIN review b ON b.institudeId=a.institudeId
WHERE a.reviewId='3';
update table institutions
set averageRatings=avg(b.averageRating)
where id=a.institudeId;
更新mysql查询:
SELECT avg(b.averageRating)
FROM review a INNER
JOIN review b ON b.institudeId=a.institudeId
WHERE a.reviewId='3';
update table institutions
set averageRatings=avg(b.averageRating)
where id=a.institudeId;
您可以尝试以下查询:
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'
)
这是更好的解决办法。