我有这两个表,第一个叫item_coordinates,类型是INT, DOUBLE, DOUBLE
itemID | latitude | longitude
-------------+-----------+-----------
1679323860 | 36.531398 | -82.98085
1679340420 | 29.178171 | -74.075391
1679386982 | 40.73235 | -94.6884
现在我有另一个名为 Geocoordinates 的表,我按如下方式创建了这个表:
CREATE TABLE Geocoordinates (ItemID INT PRIMARY KEY,
Geo_Coordinates POINT) ENGINE = MyISAM;
现在我想将表 1 中的值插入到表 2 中,但不断收到错误消息。这是我的尝试:
INSERT INTO Geocoordinates (ItemID, Geo_Coordinates) VALUES (item_id,
POINT(latitude, longitude)) SELECT item_id, latitude, longitude FROM
item_coordinates);
提前致谢。
最佳答案
我认为您需要使用 CONCAT 函数将纬度/经度分组到一个字段中
INSERT INTO Geocoordinates (ItemID, Geo_Coordinates) VALUES (item_id,
POINT(latitude, longitude)) SELECT item_id, CONCAT(latitude, longitude) FROM item_coordinates);
我认为在这种情况下不需要 POINT。
关于mysql - 如何在 mysql 中将一个表作为值插入到另一个表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35881668/