문제

I have 2 lists of postcodes, one origins and the other destinations:

Origins

  1. firstOrigin
  2. secondOrigin
  3. thirdOrigin

Destinations

  1. firstDestination
  2. secondDestination
  3. thirdDestination

I want to be able to import these to a mysql database so they are imported as single records for each journey. So the final results will be (where Origin and Destination are columns in the table):

Origin Destination

firstOrigin firstDestination


firstOrigin secondDestination


firstOrigin thirdDestination


secondOrigin firstDestination


secondOrigin secondDestination


secondOrigin thirdDestination


thirdOrigin firstDestination


thirdOrigin secondDestination


thirdOrigin thirdDestination


Apologies if this is unclear. It's difficult to display a table on here!

도움이 되었습니까?

해결책

Follow this question for importing data from CSV to mysql. You have to have two tables origins and distinations or better yet create temporary tables origins and distinations. Once you have imported data in mysql, You can get your result by applying cross product on both tables like this

INSERT INTO yourResultingTable
    (origins, destinations)
    SELECT origins.origin, destination.destination FROM origins, destinations;

다른 팁

Try this :

INSERT INTO global_table (origin, destination)
SELECT origin_column, destination_column
FROM origin, destination
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top