如何使用公共列连接两个表中的所有组合

Ala*_*lan 2 join ms-access

我有一份供应国家/地区名单的供应商名单。例如:

供应商 A 供应给:

  1. 美国
  2. 法国
  3. 中国

以及另一份供应商及其供应商工厂清单 例如:

供应商 A 制造:

  1. 英国
  2. 德国

如何构建(供应商、国家、工厂)的所有可能组合的列表(按行)?我有超过 10.000 个供应商。例如,对于供应商 A:

  1. 美国-英国,
  2. 美国-德国
  3. 法国-英国
  4. 法德
  5. 中英
  6. 中德

有人可以帮我解决这个问题吗?我已经尝试使用 Excel 和 Access 进行了数周的研究。

Pau*_*ite 6

使用 SQL Server,因为我没有安装 Access,希望这足够通用,对你有用:

示例表和数据

CREATE TABLE SupplierCountry
(
    SupplierName varchar(50) NOT NULL,
    CountryName varchar(50) NOT NULL
);

INSERT SupplierCountry
    (SupplierName, CountryName)
VALUES
    ('Supplier A', 'USA'),
    ('Supplier A', 'France'),
    ('Supplier A', 'China');
Run Code Online (Sandbox Code Playgroud)

供应商国家

??????????????????????????????
? SupplierName ? CountryName ?
??????????????????????????????
? Supplier A   ? USA         ?
? Supplier A   ? France      ?
? Supplier A   ? China       ?
??????????????????????????????
Run Code Online (Sandbox Code Playgroud)

供应商工厂

CREATE TABLE SupplierFactory
(
    SupplierName varchar(50) NOT NULL,
    CountryName varchar(50) NOT NULL
);

INSERT SupplierFactory
    (SupplierName, CountryName)
VALUES
    ('Supplier A', 'UK'),
    ('Supplier A', 'Germany');

??????????????????????????????
? SupplierName ? CountryName ?
??????????????????????????????
? Supplier A   ? UK          ?
? Supplier A   ? Germany     ?
??????????????????????????????
Run Code Online (Sandbox Code Playgroud)

询问:

SELECT
    SC.SupplierName AS Supplier,
    SC.CountryName AS SupplyCountry,
    SF.CountryName AS FactoryCountry
FROM SupplierCountry AS SC
JOIN SupplierFactory AS SF
    ON SF.SupplierName = SC.SupplierName;
Run Code Online (Sandbox Code Playgroud)

输出:

???????????????????????????????????????????????
?  Supplier  ? SupplyCountry ? FactoryCountry ?
???????????????????????????????????????????????
? Supplier A ? USA           ? UK             ?
? Supplier A ? France        ? UK             ?
? Supplier A ? China         ? UK             ?
? Supplier A ? USA           ? Germany        ?
? Supplier A ? France        ? Germany        ?
? Supplier A ? China         ? Germany        ?
???????????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)