MySQL, along with most other flavors of SQL, does not allow referring to an alias in the WHERE
clause defined in a select at the same level of the query. So, your WHERE
clause is invalid. Fortunately MySQL has overloaded its HAVING
operator to allow referring to an alias, so you may try that:
SELECT * , ACOS( SIN( RADIANS( lat )) * SIN( RADIANS( 37.387138 )) +
COS( RADIANS( lat )) * COS( RADIANS( 37.387138 )) * COS( RADIANS( lng )
- RADIANS( -122.083237 )) ) * 6380 AS distance
FROM restaurants
HAVING distance < 10
ORDER BY distance;
Also note that your restaurants
table, and lat
/lng
columns, should not be in single quotes.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…