如何使用此MySQL select语句在另一个表中插入行?

时间:2011-08-26 16:40:25

标签: mysql select

如何使用此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的表中。其结构如下:

  • 邻里(varchar 50)
  • result(tinyint 1)
  • reportdatetime (日期时间)
  • 纬度(十进制11,9)
  • 经度(十进制10,8)
  • sport_type(varchar 30)

2 个答案:

答案 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;