0
我的數據庫中有位於16英里的Blocks Realty記錄。無法在HAVING子句中添加條件以進行查詢
SELECT x.companyname, x.distance, y.city, y.zip
FROM (SELECT userid, companyname, lat, lng,
(3959 * acos(cos(radians(42.323617)) *
cos(radians(lat)) * cos(radians(lng) - radians(-83.200811)) +
sin(radians(42.323617)) * sin(radians(lat)))) AS distance
FROM users
WHERE (usertype = 2 OR usertype = 3)
HAVING distance < 25
order by distance) x
INNER JOIN
(select * from users where find_in_set('Real Estate',profession) <> 0) y
ON x.userid = y.userid
當我更新下面的查詢新增的城市或拉鍊狀況,減少距離搜索範圍,我得到的錯誤#1054 - 未知列「城市」「having子句」中。我該如何糾正?
SELECT x.companyname, x.distance, y.city, y.zip
FROM (SELECT userid, companyname, lat, lng,
(3959 * acos(...) AS distance
FROM users
WHERE (usertype = 2 OR usertype = 3)
HAVING distance < 11
AND (city = 'Detroit' OR zip = '48221')
order by distance) x
INNER JOIN
(select * from users where find_in_set('Real Estate',profession) <> 0) y
ON x.userid = y.userid
謝謝你的回覆。現在我只記得底特律作爲城市。我需要將這些記錄添加到距離小於11的其他記錄。 –
這很有效。再次感謝 –