我有此查询,它运行良好
从此查询中,我从我的位置(这是我的第一张表)中选择所有3 KM的餐厅。
SELECT foodjoint_id,foodjoint_name,open_hours,cont_no,address_line,city ( 3959 * acos( cos( radians('".$userLatitude."') ) * cos( radians( foodjoint_latitude) ) * cos( radians( foodjoint_longitude) - radians('".$userLongitude."') ) + sin( radians('".$userLatitude."') ) * sin( radians( foodjoint_latitude) ) ) ) AS distance FROM provider_food_joints HAVING distance < '3' ORDER BY distance LIMIT 0 , 20
但是我需要从3Km中的食品接头中选择AVG等级。
该查询也运行完美:
select AVG(customer_ratings) from customer_review where foodjoint_id=".$foodjoint_id
但是我需要添加这两个查询,通过它们我可以选择所有那些食品接头及其等级AVG。
只需放置子查询,您将得到结果:
`SELECT foodjoint_id,foodjoint_name,open_hours,cont_no,address_line,city ( 3959 * acos( cos( radians('".$userLatitude."') ) * cos( radians( foodjoint_latitude) ) * cos( radians( foodjoint_longitude) - radians('".$userLongitude."') ) + sin( radians('".$userLatitude."') ) * sin( radians( foodjoint_latitude) ) ) ) AS distance, (select AVG(customer_ratings) from customer_review where customer_review.foodjoint_id=provider_food_joints.foodjoint_id) as Customer_Reviews FROM provider_food_joints HAVING distance < '3' ORDER BY distance LIMIT 0 , 20`