开发者

How can I insert rows in another table using this MySQL select statement?

How can I use the results of this select statement to insert rows in another table?

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;

I'd like to put the results of this Select into a table called sports_by_neighborhood. Its structure is as follows:

  • neighborhoods (varchar 50)
  • result (tinyint 1)
  • reportdatetime (datetime)
  • la开发者_JAVA百科titude (decimal 11,9)
  • longitude (decimal 10,8)
  • sport_type (varchar 30)


Simply use the insert select syntax:

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;


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜