如何使用此select语句的结果在另一个表中插入行?
SELECT "Old Town" AS neighborhoods, reportdatetime, IS_POINT_IN_POLYGON(
POINTFROMTEXT( CONCAT( 'POINT(', latitude, ' ', longitude, ')' ) ) , POLYFROMTEXT( 'POLYGON((38.91911 -77.03648000000001,
38.918150000000004 -77.03979000000001,
38.917910000000006 -77.0403,
38.91734 -77.04073000000001,
38.91911 -77.03648000000001
))' )
)AS result, latitude, longitude, sport_type
FROM sport
WHERE IS_POINT_IN_POLYGON(
POINTFROMTEXT( CONCAT( 'POINT(', latitude, ' ', longitude, ')' ) ) , POLYFROMTEXT( 'POLYGON((38.91911 -77.03648000000001,
38.918150000000004 -77.03979000000001,
38.917910000000006 -77.0403,
38.91734 -77.04073000000001,
38.91911 -77.03648000000001 ))' )
) = 1;
我想把这个Select的结果放到一个名为sports_by_neighborhood的表中。其结构如下:
答案 0 :(得分:2)
只需使用insert select语法:
INSERT INTO other_table ( neighborhoods, reportdatetime, result, latitude, longitude, sport_type )
SELECT "Old Town" AS neighborhoods, reportdatetime, IS_POINT_IN_POLYGON(
POINTFROMTEXT( CONCAT( 'POINT(', latitude, ' ', longitude, ')' ) ) , POLYFROMTEXT( 'POLYGON((38.91911 -77.03648000000001,
38.918150000000004 -77.03979000000001,
38.917910000000006 -77.0403,
38.91734 -77.04073000000001,
38.91911 -77.03648000000001
))' )
)AS result, latitude, longitude, sport_type
FROM sport
WHERE IS_POINT_IN_POLYGON(
POINTFROMTEXT( CONCAT( 'POINT(', latitude, ' ', longitude, ')' ) ) , POLYFROMTEXT( 'POLYGON((38.91911 -77.03648000000001,
38.918150000000004 -77.03979000000001,
38.917910000000006 -77.0403,
38.91734 -77.04073000000001,
38.91911 -77.03648000000001 ))' )
) = 1;
答案 1 :(得分:0)
INSERT INTO sports_by_neighborhood (neighborhoods, reportdatetime, result, latitude,longitude, sport_type)
SELECT "Old Town" AS neighborhoods, reportdatetime, IS_POINT_IN_POLYGON(
POINTFROMTEXT( CONCAT( 'POINT(', latitude, ' ', longitude, ')' ) ) , POLYFROMTEXT( 'POLYGON((38.91911 -77.03648000000001,
38.918150000000004 -77.03979000000001,
38.917910000000006 -77.0403,
38.91734 -77.04073000000001,
38.91911 -77.03648000000001
))' )
)AS result, latitude, longitude, sport_type
FROM sport
WHERE IS_POINT_IN_POLYGON(
POINTFROMTEXT( CONCAT( 'POINT(', latitude, ' ', longitude, ')' ) ) , POLYFROMTEXT( 'POLYGON((38.91911 -77.03648000000001,
38.918150000000004 -77.03979000000001,
38.917910000000006 -77.0403,
38.91734 -77.04073000000001,
38.91911 -77.03648000000001 ))' )
) = 1;