2017-05-29 87 views
2

我對sql很新,我需要結合具有不同佈局的兩個表的幫助。這是我的一個例子。我的第一個表是:將不同佈局的兩張表合併爲一個MS-Access

Employee's of Jim Data 

|year| retired | Other 
|2013| 23 | 32 
|2014| 12 | 5 
|2015| 13 | 8 

我的第二個表是:

|Director| retire 2016 | retire 2017| Other 2016 | Other 2017| 
| tony |.............|............|............|...........| 
| Jim | 23  | 54  | 12  |  22 | 

我想我得到的表有佈局(我的第一個表)「吉姆數據的員工」一樣,它會追加我的第二張表中Director =「Jim」的數據。所以它應該看起來像這樣:

|year| retired | Other 
|2013| 23 | 32 
|2014| 12 | 5 
|2015| 13 | 8 
|2016| 23 | 12 
|2017| 54 | 22 

任何幫助將是偉大的!提前致謝!

回答

2

需要兩個不同的查詢來自這兩個表的獲得可比較的數據,然後使用union all合併的結果

/* from the first table */ 
select year, retired, Other 
from table1 
union all 
/* from the second table */ 
select '2016', retire_2016, other_2016 
from table2 
where Director = 'Jim' 
union all 
select '2017', retire_2017, other_2017 
from table2 
where Director = 'Jim' 
+0

謝謝!工作 – tee

+0

不客氣,很高興它幫助:) –

相關問題