我必须在 table1 中为 table2 中找到的每一行插入一个新行。问题是 table2 中的 select 返回的字段多于插入所需的字段,但在 select 的 where 子句中很有用。
此查询根据他们的 (shops) 范围(在表 stores 中定义)向用户显示周围的所有商店
SELECT destination.poi_id,
6371 *
2 *
ASIN(
SQRT(
POWER(SIN((use_lat - poi_lat) * PI()/180 / 2), 2) +
COS(use_lat * pi()/180) *
COS(poi_lat * pi()/180) *
POWER(SIN((use_lon - poi_lon) * PI()/180 / 2), 2)
)
) AS distance,
destination.poi_range AS range
FROM stores destination, users origin
WHERE origin.use_id=userid
AND destination.poi_lon BETWEEN lon1 AND lon2
AND destination.poi_lat BETWEEN lat1 AND lat2
HAVING distance <= range
ORDER BY distance;
现在我必须将这些结果放在具有这种结构的表中
user_id INTEGER
poi_id INTEGER
ins_date TIMESTAMP (CURRENT TIMESTAMP)
我不知道该怎么做,你能帮帮我吗?
INSERT INTO table (user_id, poi_id)
SELECT ... ? (too many fields in select)