我试图通过平均评论评级列来获得半径内平均评级最高的主题。
我已经尝试了一些类似的东西:
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