Ms-Access

MS Access 2007:組合表中的數據導致數據組合

  • August 15, 2017

所以我在 Microsoft Access 2007 中的查詢是從三個不同的表中獲取數據:a、b、c。在這些表中,所有命名為“時間”的雙精度值都被執行以記錄事件發生的時間。以下是我目前對每個表的值:

a.Time: 7.776, 117.7144, 3.0921, 6.8509
b.Time: 11.0392, 11.8620, 111.1510, 14.2148, 14.2899, 7.8790
c.Time: 2.3672, 115.9478, 117.3253

我試圖做的是將所有這些雙打放在一個名為“時間”的列中。這是我希望得到的(對它們進行排序是一個加號):

   Time
------------
 7.776
 117.7144
 3.0921
 6.8509
 11.0392
 11.8620
 111.1510
 14.2148
 14.2899
 7.8790
 2.3672
 115.9478
 117.3253

到目前為止,我所做的是將每個雙打放入自己的列中,希望它至少會顯示最多 6 行,顯示各自表格中的所有時間。然而,這就是我最終的結果:

a Time    b Time    c Time
---------------------------
7.776     11.0392   2.3672
7.776     11.8620   2.3672
7.776     111.1510  2.3672
7.776     14.2148   2.3672
7.776     14.2899   2.3672
7.776     7.8790    2.3672
117.7144  11.0392   2.3672
117.7144  11.8620   2.3672
117.7144  111.1510  2.3672
117.7144  14.2148   2.3672
117.7144  14.2899   2.3672
117.7144  7.8790    2.3672
3.0921    11.0392   2.3672
3.0921    11.8620   2.3672
3.0921    111.1510  2.3672
3.0921    14.2148   2.3672
3.0921    14.2899   2.3672
3.0921    7.8790    2.3672
6.8509    11.0392   2.3672
6.8509    11.8620   2.3672
6.8509    111.1510  2.3672
6.8509    14.2148   2.3672
6.8509    14.2899   2.3672
6.8509    7.8790    2.3672
7.776     11.0392   115.9478
7.776     11.8620   115.9478
7.776     111.1510  115.9478
7.776     14.2148   115.9478
7.776     14.2899   115.9478
7.776     7.8790    115.9478
117.7144  11.0392   115.9478
117.7144  11.8620   115.9478
117.7144  111.1510  115.9478
117.7144  14.2148   115.9478
117.7144  14.2899   115.9478
117.7144  7.8790    115.9478
3.0921    11.0392   115.9478
3.0921    11.8620   115.9478
3.0921    111.1510  115.9478
3.0921    14.2148   115.9478
3.0921    14.2899   115.9478
3.0921    7.8790    115.9478
6.8509    11.0392   115.9478
6.8509    11.8620   115.9478
6.8509    111.1510  115.9478
6.8509    14.2148   115.9478
6.8509    14.2899   115.9478
6.8509    7.8790    115.9478
7.776     11.0392   117.3253
7.776     11.8620   117.3253
7.776     111.1510  117.3253
7.776     14.2148   117.3253
7.776     14.2899   117.3253
7.776     7.8790    117.3253
117.7144  11.0392   117.3253
117.7144  11.8620   117.3253
117.7144  111.1510  117.3253
117.7144  14.2148   117.3253
117.7144  14.2899   117.3253
117.7144  7.8790    117.3253
3.0921    11.0392   117.3253
3.0921    11.8620   117.3253
3.0921    111.1510  117.3253
3.0921    14.2148   117.3253
3.0921    14.2899   117.3253
3.0921    7.8790    117.3253
6.8509    11.0392   117.3253
6.8509    11.8620   117.3253
6.8509    111.1510  117.3253
6.8509    14.2148   117.3253
6.8509    14.2899   117.3253
6.8509    7.8790    117.3253

如您所見,我得到了每行中所有時間組合的 72 行(4 x 6 x 3)。有人對如何解決這個問題有任何想法嗎?

編輯:根據之前的評論,我在這裡發布了我的全部程式碼。

SELECT N.[Precursor m/z], N.[a Time], N.[b Time], c.[Time] AS [c Time], N.
      [Glycan ID], N.[Glycan Sequence]
FROM (
  SELECT a.[Precursor m/z], a.[Time] AS [a Time], b.[Time] AS [b Time], 
         a.[Glycan ID], a.[Glycan Sequence] FROM a 
  INNER JOIN b ON a.[Precursor m/z]=b.[Precursor m/z])  AS N 
INNER JOIN c ON N.[Precursor m/z]=c.[Precursor m/z];

如果有重複的值,您想要兩個(+)結果還是只有一個?

如果您想要所有結果:

SELECT Time FROM a
UNION ALL
SELECT Time FROM b
UNION ALL
SELECT Time FROM c

如果您只想要獨特的結果:

SELECT Time FROM a
UNION
SELECT Time FROM b
UNION
SELECT Time FROM c

引用自:https://dba.stackexchange.com/questions/183476