0

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)
  • latitude (decimal 11,9)
  • longitude (decimal 10,8)
  • sport_type (varchar 30)
1

2 Answers 2

2

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;
Sign up to request clarification or add additional context in comments.

Comments

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.