MySQL查詢內的選擇數據:MySQL的百公里
select pet_info.pet_user_id as userid,
pet_info.pet_cat,pet_info.pet_breed as petbreed,
lostpets.pet_reward,lostpets.currency,pet_info.pet_name as name,
lostpets.pet_lost_date as date,
lostpets.pet_city,lostpets.petid as pid,
lostpets.id as lid,lostpets.type,lostpets.pet_lost_location,lostpets.pet_lost_address,lostpets.pet_postal,lostpets.pet_country
,(6371 * ACOS(COS(RADIANS('23.0862143')) * COS(RADIANS( `pet_lat`)) * COS(RADIANS( `pet_long`) - RADIANS('72.59330969999996')) + SIN(RADIANS('23.0862143')) * SIN(RADIANS( `pet_lat`)))) AS `distance`
from lostpets as lostpets
LEFT JOIN pet_info as pet_info ON lostpets.petid=pet_info.id
where lostpets.active='Active' AND `distance` < 100 order by `distance` asc
該查詢由兩個lat和長之間顯示距離。但我想選擇100公里範圍內的數據。我該如何做到這一點,請幫助我。
添加別名到距離計算等''''AS distance'''',然後在其中子句添加''''與距離<100'''。 –
'where子句'中的未知列'distance' –