无法获得此查询的前5名食物。计算那家餐厅的前5种食物。
<?php
header('Content-Type: application/json');
require('config.php');
$sqlQuery = "SELECT top 5 fd.name as res_name,(SELECT count(*) from review re where re.favorite_food=fd.id and re.res_id='1' ) AS count FROM food fd ";
$result = mysqli_query($connection,$sqlQuery);
$data = array();
foreach ($result as $row) {
$data[] = $row;
}
mysqli_close($connection);
echo json_encode($data);
?>
发生错误
答案 0 :(得分:-1)
SELECT fd.name as res_name, count(*)
FROM food fd
JOIN review re ON re.favorite_food = fd.id
WHERE re.res_id = 1
GROUP BY fd.name
ORDER BY count(*) desc
LIMIT 5