我对以下查询有 sql 问题,它返回错误...
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''
我不明白为什么这会引发错误。当我删除连接的部分时,它运行正常。
此查询的工作是根据给定的位置(纬度/经度)返回一个属性列表,其中包含来自单独表的任何匹配数据以及相应offers
地存储在单独表中的城镇和县的 url slug 。如果一个属性没有特价,它仍然应该在数据中返回。towns
counties
查询是...
SELECT COUNT(agencyid) AS `count_offers`, prop.*, offers.*, twn.slug AS `slug_town`, cnty.slug AS `slug_county`, ROUND(((3959 * acos(cos(radians(50.1854670)) * cos(radians(prop.latitude)) * cos(radians(prop.longitude) - radians(-5.4209100)) + sin(radians(50.1854670)) * sin( radians(prop.latitude)))) * 2),0)/2 AS `distance`
FROM `properties` AS `prop`
JOIN `towns` AS `twn` ON twn.name=prop.town
JOIN `counties` AS `cnty` ON cnty.name=twn.county
LEFT JOIN `offers` ON offers.agencyid = prop.mID
AND
offers.dt_expire>1377985886
AND
(prop.sleeps >= offers.sleeps_min AND prop.sleeps <= offers.sleeps_max)
AND
(
prop.slug_code = offers.the_property
OR
(
(offers.the_property='' OR offers.the_property=NULL)
AND
(
(
prop.county = offers.the_county
AND
prop.town=offers.the_town
)
OR
(
prop.county = offers.the_county
AND
twn.name=offers.the_town
AND
prop.place = offers.the_place
)
OR
prop.county = offers.the_county
OR
prop.region = offers.the_region
OR
prop.country = offers.the_country
)
)
感谢您对此的帮助。