我想显示Purchase_Request的所有计数器
表Purchase_Order
counter | qty |
---------------
100001 | 10 |
100001 | 10 |
100001 | 10 |
100004 | 30 |
表Purchase_Request
counter | total_qty |
---------------------
100001 | 50 |
100002 | 100 |
100003 | 50 |
100004 | 70 |
我的代码只显示100001和100004,我想显示purchase_request中的所有计数器
select a.counter,
a.total_qty,
a.total_qty - b.qty balance
from (select counter,
sum(total_qty) total_qty
from purchase_request
group by counter) a
inner join (select counter,
sum(qty) qty
from purchase_order
group by counter) b
on a.counter= b.counter
group by a.counter
帮助?