我是mysql的初学者,你能帮我从这种情况下调用查询吗
我有两个表,我将id设为auto increment
表1:closed_route= id | name | lat
and the query is =
=1|kenjeran 1|-7.2499|-7.249
=2|mulyosari 2|-7.259|-7.259
表2: user_location
= id | lat | long1 | lat2 | long2
and the query is =
=18|-7.24945|112.783|-7.25907|112.795
表3:标记
=id | lat | lng | name
我想问的是:如何使用tables
在我的表3中插入列我使用这段代码,但结果是0,实际上该表有查询
INSERT INTO markers (lat,lng,name) SELECT user_location.lat, user_location.long1, closed_route.name
FROM user_location, closed_route
where user_location.lat LIKE CONCAT ('%', closed_route.lat, '%')LIMIT 1;
下面是该查询的一种形式:
INSERT INTO markers (lat, lng, name)
SELECT ul.lat, ul.long1, cr.name
FROM user_location ul cross join
closed_route cr
ORDER BY ABS(ul.lat - cr.lat)
LIMIT 1;
这将插入一个带有与lat
值最接近的closed_route
名称的标记。
指出:
- 此查询使用显式
join
。只是不要在from
子句中使用逗号。始终使用显式join
语法。 - 表有别名,所以查询更容易写和读。
- 在数值上不使用
like
。请使用数值函数。 - 这可能不是你想要的,但它似乎是一个合理的查询。