表private从表public继承id。我正试着在距离$lat,$lng一定距离的公共场合挑选参赛者,他们的身份证在私下里找不到。

SELECT a.id, a.data, a.lat, a.lng,
  (a_distance_function(a.lat,a.lng,$lat,$lng)) as a.distance
FROM public a
WHERE (a.lng BETWEEN $lng1 AND $lng2) AND (a.lat BETWEEN $lat1 AND $lat2)
HAVING a.distance < $dist
LEFT JOIN private b ON a.id = b.id
WHERE b.id is NULL;

但是MariaDB的错误对我没有多大帮助。语法错误near'.distance FROM USMAP a WHERE a.lng BETWEEN-xx.xxx AND-xx.xxx'

最佳答案

JOIN必须在向查询添加任何条件之前发生:

SELECT a.id, a.data, a.lat, a.lng,(a_distance_function(a.lat,a.lng,$lat,$lng)) as a.distance
FROM public a
LEFT JOIN private b
ON a.id = b.id
WHERE b.id is NULL
AND a.lng BETWEEN $lng1 AND $lng2
AND a.lat BETWEEN $lat1 AND $lat2
HAVING a.distance < $dist

关于php - 排除JOIN的左侧问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35024740/

10-10 09:09