下面我有一个查询,可以查找距离表$dist = 100;
'persons'
内)
$origLat = '8.574596';
$origLon = '-73.602050';
$dist = 100; // This is the maximum distance (in miles) away from $origLat, $origLon in which to search
$query = "SELECT id_the_person, Name, Lat, Lng, 3959 * 2 *
ASIN(SQRT( POWER(SIN(($origLat - Lat)*pi()/180/2),2)
+COS($origLat*pi()/180 )*COS(Lat*pi()/180)
*POWER(SIN(($origLon-Lng)*pi()/180/2),2)))
as distance FROM persons WHERE
Lng between ($origLon-$dist/cos(radians($origLat))*69)
and ($origLon+$dist/cos(radians($origLat))*69)
and Lat between ($origLat-($dist/69))
and ($origLat+($dist/69))
having distance < $dist ORDER BY distance limit 100";
在此查询中,我根据他们在表'svar'
SELECT *, round(count(*)/(SELECT count(*) FROM svar where id_the_person = ?)*100) as pecentage
FROM svar as l
where l.svaret=(
SELECT m.svaret
FROM svar as m
where m.id_the_person = ? and l.id_frag=m.id_frag)
group by (l.id_the_person)
order by pecentage");
两个表中的变量id_the_person
相同。我想要的是根据第一个查询匹配短按百分比但只有距离内的人的人,即第二个查询仅限于$dist=100
内的人。