0

我正在尝试在 Microsoft Access 中组合两个特殊的表格,即使在互联网上进行了大量的头脑风暴和搜索之后,我也无法这样做。

这两个表是spendexport

Spend   
+-------------+--------+-------+-------+
|     Country | Metal  | Month | Spend |
+-------------+--------+-------+-------+
|     China   | Iron   | Jan   |   100 |
|     China   | Iron   | Feb   |   200 |
|     China   | Iron   | March |   300 |
|     India   | Iron   | Jan   |   400 |
|     India   | Copper | April |   500 |
|     Spain   | Zinc   | June  |   600 |
+-------------+--------+-------+-------+

Export
+-------------+-------+------+--------+
|     Country | Metal | Year | Export |
+-------------+-------+------+--------+
|     China   | Iron  | 2001 | 2,000  |
|     India   | Iron  | 2002 | 4,000  |
|     India   | Iron  | 2003 | 5,000  |
|     Spain   | Zinc  | 2011 | 3,500  |
|     Spain   | Zinc  | 2012 | 4,000  |
|     Spain   | Zinc  | 2013 | 9,000  |
+-------------+-------+------+--------+

所需组合表

+-------------+--------+-------+-------+------+--------+
|     Country | Metal  | Month | Spend | Year | Export |
+-------------+--------+-------+-------+------+--------+
|     China   | Iron   | Jan   |   100 | 2001 | 2,000  |
|     China   | Iron   | Feb   |   200 |      |        |
|     China   | Iron   | March |   300 |      |        |
|     India   | Iron   | Jan   |   400 | 2002 | 4,000  |
|     India   | Iron   |       |       | 2003 | 5,000  |
|     India   | Copper | April |   500 |      |        |
|     Spain   | Zinc   | June  |   600 | 2011 | 3,500  |
|     Spain   | Zinc   |       |       | 2012 | 4,000  |
|     Spain   | Zinc   |       |       | 2013 | 9,000  |
+-------------+--------+-------+-------+------+--------+
4

1 回答 1

1

鉴于您的输入表,您将通过直接 Select 查询获得最接近的是

SELECT 
    Spend.Country, 
    Spend.Metal, 
    Spend.Month, 
    Spend.Spend, 
    Export.Year, 
    Export.Export
FROM 
    Export 
    RIGHT JOIN 
    Spend 
        ON (Export.Metal = Spend.Metal) 
        AND (Export.Country = Spend.Country)
ORDER BY 
    Spend.Country, 
    Spend.Metal, 
    CDate("2010-" & [Spend].[Month] & "-01"), 
    Export.Year;

该查询返回

Country  Metal   Month  Spend  Year  Export
-------  ------  -----  -----  ----  ------
China    Iron    Jan      100  2001    2000
China    Iron    Feb      200  2001    2000
China    Iron    March    300  2001    2000
India    Copper  April    500              
India    Iron    Jan      400  2002    4000
India    Iron    Jan      400  2003    5000
Spain    Zinc    June     600  2011    3500
Spain    Zinc    June     600  2012    4000
Spain    Zinc    June     600  2013    9000

...其中包括您指定的行。但是,它不会抑制从一行到下一行的重复 Month/Spend 和 Year/Export 值,但这是可以在报告中完成的。

于 2013-10-18T16:22:07.903 回答