我试图通过平均评论评分栏来获得半径范围内平均评分最高的科目。
我尝试过以下方面:
select avg(`rating`) AS `avgrate` , subject.*,
, ( 3959 * acos( cos( radians(22.28639) ) * cos( radians( lat ) ) * cos( radians( subject.long ) - radians(114.1491) ) + sin( radians(22.28639) ) * sin( radians( lat ) ) ) )
AS distance
from `subject_review`
JOIN `subject`
ON subject_review.subject_id = subject.id
group by `subject_id`
HAVING distance <= 100
order by `avgrate` DESC
LIMIT 10
这个SQL工作正常,我只需要添加半径过滤器,
select avg(`rating`) AS `avgrate` ,subject_review.id , subject.*
from `subject_review`
JOIN `subject`
ON subject_review.subject_id = subject.id
group by `subject_id`
order by `avgrate` DESC
LIMIT 10