简体   繁体   English

在mysql中创建记录

[英]Creating records in mysql

I have 2 lists of postcodes, one origins and the other destinations: 我有2个邮政编码列表,一个是起点,另一个是终点:

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. 我希望能够将这些导入到mysql数据库中,以便将它们作为每个旅程的单个记录导入。 So the final results will be (where Origin and Destination are columns in the table): 因此,最终结果将是(其中Origin和Destination是表中的列):

Origin Destination 出发地

firstOrigin firstDestination firstOriginfirstDestination


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! 在这里很难显示表格!

Try this : 尝试这个 :

INSERT INTO global_table (origin, destination)
SELECT origin_column, destination_column
FROM origin, destination

Follow this question for importing data from CSV to mysql . 遵循此问题将数据从CSV导入mysql You have to have two tables origins and distinations or better yet create temporary tables origins and distinations . 您必须具有两个表的originsdistinations或者更好地创建临时表的originsdistinations Once you have imported data in mysql, You can get your result by applying cross product on both tables like this 在mysql中导入数据后,可以通过在两个表上应用叉乘积来获得结果

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM