创建SQL查询以将table1列条目复制到table2列条目时遇到问题。
情景是,
城市是一个包含以下属性的表
Venue 是一个包含以下属性的表
我要复制所有纬度&经度进入 lat& 分别 lat& long 应该为NULL,当city为Active = 1且c.city_id = v.city_id时。 但是Venue中存在多个city_id,因此我需要复制它。
如果有人帮助我为此构建查询,那将会很有帮助。
答案 0 :(得分:1)
您可以在UPDATE
JOIN
语句
UPDATE Venue
INNER JOIN City ON City.City_Id = Venue.City_Id
SET Venue.lat = City.latitude, Venue.long = City.longitude
WHERE City.Active = 1 AND (Venue.lat IS NULL OR Venue.long IS NULL)
答案 1 :(得分:1)
对UPDATE
JOIN
查询
UPDATE Venue AS v
JOIN City AS c ON v.city_id = c.city_id
SET v.lat = c.latitude, v.long = c.longitude
WHERE c.active = 1 AND v.lat IS NULL AND v.long IS NULL