如何获得距离< 500?

时间:2011-06-01 09:24:59

标签: php mysql

这是我使用纬度经度值计算距离的查询。

SELECT mm.mem_id, mm.profilenam, mm.photo_thumb, mm.city, mm.zip, mm.country, mm.state, ( 3956 *2 * ASIN( SQRT( POWER( SIN( ( 34.1012181 - ABS( latitude ) ) * PI( ) /180 /2 ) , 2 ) + COS( 34.1012181 * PI( ) /180 ) * COS( ABS( latitude ) * PI( ) /180 ) * POWER( SIN( (
ABS( - 118.325739 ) - ABS( longitude ) ) * PI( ) /180 /2 ) , 2 ) ) )
) AS distance
FROM members AS mm
WHERE mm.profile_type =  'C'
ORDER BY distance
LIMIT 0 , 10

我想要距离< 500但是当我提出查询 ...< 500 AS距离,它不起作用 我怎样才能得到最终的查询。

2 个答案:

答案 0 :(得分:2)

你试过吗

SELECT mm.mem_id, mm.profilenam, mm.photo_thumb, mm.city, mm.zip, mm.country, mm.state, ( 3956 *2 * ASIN( SQRT( POWER( SIN( ( 34.1012181 - ABS( latitude ) ) * PI( ) /180 /2 ) , 2 ) + COS( 34.1012181 * PI( ) /180 ) * COS( ABS( latitude ) * PI( ) /180 ) * POWER( SIN( (
ABS( - 118.325739 ) - ABS( longitude ) ) * PI( ) /180 /2 ) , 2 ) ) )
) AS distance
FROM members AS mm
WHERE mm.profile_type =  'C'
HAVING distance<500

答案 1 :(得分:0)

由于这是派生列,您需要使用HAVING子句

SELECT mm.mem_id, mm.profilenam, mm.photo_thumb, mm.city, mm.zip, mm.country, mm.state, ( 3956 *2 * ASIN( SQRT( POWER( SIN( (        34.1012181 - ABS( latitude ) ) * PI( ) /180 /2 ) , 2 ) + COS( 34.1012181 * PI( ) /180 ) * COS( ABS( latitude ) * PI( ) /180 ) *   POWER( SIN( (
ABS( - 118.325739 ) - ABS( longitude ) ) * PI( ) /180 /2 ) , 2 ) ) )
) AS distance
FROM members AS mm
WHERE mm.profile_type =  'C'

HAVING distance < 500

ORDER BY distance
LIMIT 0 , 10