如何编写一个SQl查询以使用Table1和Table2创建“ NewTable”,其结果类似于下面的“ NewTable”?

   Table1
 EmmployeeID
|     1     |
|     2     |
|     3     |

  Table2
 AgencyID
|   a    |
|   b    |
|   c    |

              NewTable
      |EmmployeeID|AgencyID|
      |     1     |   a    |
      |     1     |   b    |
      |     1     |   c    |
      |     2     |   a    |
      |     2     |   b    |
      |     2     |   c    |
      |     3     |   a    |
      |     3     |   b    |
      |     3     |   c    |

最佳答案

创建第三个表,然后通过执行INSERTCROSS JOINTable1Table2

CREATE TABLE NewTable
(
  EmployeeID int,
  AgencyID varchar,
);

INSERT INTO NewTable
select EmployeeID, AgencyID
from Table1 CROSS JOIN Table2

关于mysql - SQL查询:为每个项目添加多个值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39903879/

10-10 20:09