【发布时间】:2017-11-18 18:13:23
【问题描述】:
世界。
我在这里有两个表,分别称为驱动程序和签到。 checkin 表的 d_id 字段保存了驱动表中条目的 id。
在我的查询中,我尝试加入表并对加入的表执行 where 条件。
到目前为止,我有这个查询(我无法加入表,加入表上的 where 部分是在我实现这一点之后出现的)
SELECT checkin.id, checkin.d_id, checkin.place, ( 3959 * acos( cos( radians(8.9551889) ) * cos( radians( lati ) )
* cos( radians( longi ) - radians(76.9902276) ) + sin( radians(8.9551889) ) * sin(radians(lati)) ) ) AS distance
FROM checkin WHERE status != 1
INNER JOIN drivers ON drivers.id = checkin.d_id
HAVING distance < 10
ORDER BY distance
LIMIT 0 , 20
这个查询在没有内部连接的情况下工作,但我不确定我在这里做错了什么。如果有人能指出来,那会很有帮助。 谢谢。
【问题讨论】:
-
如果您使用 where 子句,则无需写“Having”。你没有使用 group by 所以有和 where 子句的工作方式相同。在内连接后也使用 where 子句。 --- 如果您的驱动程序表没有返回数据而不是您希望结果使用左连接。