我正在嘗試以下操作。從另一個表中的特定行獲取一個表的平均值php
從名爲醫院的表中選擇id = hid的醫院。 從命名爲hrating
這裏另一個表中添加值「overall_rating」給它,並得到所有的收視率,並利用它的魅力是我的查詢
$statement = $conn->prepare('SELECT hospital.*,(SELECT AVG(hrating.rating_h) FROM hrating WHERE hid = hospital.hid) as overall_rating WHERE hid=:hid LIMIT 1');
收到此錯誤
{"error":"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE hid='44' LIMIT 1' at line 1"}
我在哪裏錯了。