我有多个表,帐号和金额。
表名: 7月帐户
| Account Number | Amount |
|------------------|--------|
| 1111111111111111 | $99.00 |
表名:八月帐户
| Account Number | Amount |
|------------------|--------|
| 2222222222222222 | $89.00 |
我希望我的结果显示为:
| Account Number | July | August |
|------------------|--------|--------|
| 1111111111111111 | $99.00 | - |
| 2222222222222222 | - | $89.00 |
到目前为止,我所尝试过的所有内容都会产生以下结论:
| Account Number | July | August |
|------------------|--------|--------|
| 1111111111111111 | $99.00 | $89.00 |
| 1111111111111111 | $99.00 | $99.00 |
| 1111111111111111 | $89.00 | $89.00 |
| 1111111111111111 | $89.00 | $99.00 |
| 2222222222222222 | $99.00 | $89.00 |
| 2222222222222222 | $99.00 | $99.00 |
| 2222222222222222 | $89.00 | $89.00 |
| 2222222222222222 | $89.00 | $99.00 |
有什么建议吗?
答案 0 :(得分:2)
你只需要使用UNION:
SELECT Account_Number, Amount as July, null as August
FROM July_Accounts
UNION
SELECT Account_Number, null, Amount
FROM August_Accounts