0

以下のクエリで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 ''

これがエラーをスローする理由がわかりません。結合の一部を削除すると、正しく実行されます。

このクエリの仕事は、指定された場所 (緯度/経度) に基づいてプロパティのリストを、別のテーブルに格納されている町と郡の URL スラッグと共に、別のテーブルからの一致するデータと共に返すことoffersです。プロパティに特別オファーがない場合でも、データで返されるはずです。townscounties

クエリは...

    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
    )
  )

これについて助けてくれてありがとう。

4

3 に答える 3

1

MySQL では、比較する必要がある場合NULL、構文は次のとおりです。Colunname IS NULL

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 IS 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
    )
  )
)
于 2013-09-02T11:56:43.070 に答える