【发布时间】:2015-09-25 09:53:48
【问题描述】:
我不知道标题应该如何。考虑标题比写这个问题需要更多的时间。
重点
假设我有三个表:
//table customers
| ID | Name |
++++++++++++++++++++++++++++++++
| 194 | PT Comro Haneut |
| 195 | PT Kareueut Kameumeut |
//table customer's savings
| ID | IDCustomer | SavingsAmount |
+++++++++++++++++++++++++++++++++++++
| 1 | 194 | 5000000 |
| 2 | 195 | 250000 |
| 3 | 195 | 2500000 |
| 4 | 194 | 125000 |
| 5 | 194 | 175000 |
//table transactions
| ID | IDCustomer | Amount |
+++++++++++++++++++++++++++++++++++++
| 1 | 195 | 1000000 |
| 2 | 195 | 250000 |
| 3 | 194 | 3500000 |
| 4 | 194 | 300000 |
目标
我想将储蓄金额和交易金额相加,并将结果放在一行中,如下所示:
// expected result of the query
| IDCustomer | Savings | Transactions | Balance |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| 194 | 5300000 | 4800000 | 500000 |
| 195 | 2750000 | 1250000 | 1500000 |
我尝试自己构建查询,但总是失败。我得到了节省的总金额,交易量翻了一番。
谁能帮忙?
【问题讨论】: