0
我想兩個查詢結果MySQL查詢:我想2個查詢結果合併WRT主鍵
select refno,sum(rate*quantity-recieved) from ledger;
總帳表
+--------+---------------------------------------+
| refno | sum(quantity*rate-recieved) |
+--------+---------------------------------------+
| 1/13 | -190 |
| 10/13 | 3710 |
| 100/13 | 625 |
| 101/13 | 30 |
| 102/13 | 0 |
+--------+---------------------------------------+
和
select deposit from customer;
客戶
+--------+---------+
| refno | deposit |
+--------+---------+
| 1/13 | -10 |
| 10/13 | 500 |
| 100/13 | 0 |
| 101/13 | 250 |
| 102/13 | 1000 |
+--------+---------+
將被組合用於該輸出;總=(customer.deposit-(ledger.rate * ledger.quantity-ledger.received))
refno | total
1/13 | -200
10/13 | 4210
100/13| 625
101/13| 280
102/13| 1000
你真的有一個表,其中列名是'sum(quantity * rate-received)'? –
@GordonLinoff:當你在MySQL中調用函數並且不給它別名時會發生這種情況。 –
umm ...你是不是錯過了第一個查詢中的'group by'子句? – Mureinik