我不知道標題應該如何。對標題的思考比寫這個問題需要更多的時間。
給點
假設我有三個表:如何查詢SUM連接表?
//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 |
我試圖建立由我自己的查詢,但我總是失敗。我得到的儲蓄和交易總額增加了一倍。
任何人都可以幫忙嗎?
就是這樣!子查詢是答案:D –