我想要两个查询结果
select refno,sum(rate*quantity-recieved) from ledger;
Ledger Table
+--------+---------------------------------------+
| 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
答案 0 :(得分:0)
select ledger.refno, (sum(ledger.rate*ledger.quantity-recieved) - customer.deposit) AS total from ledger
INNER JOIN customer
ON customer.refno = ledger.refno
我认为这应该有用......