原始表store:
in | buy |
A | 1000 |
B | 2000 |
原始表market:
id | sell |
A | 100 |
A | 200 |
A | 300 |
B | 500 |
B | 400 |
SQL 语句如下:
select in, buy-sold from store, (select id, sum(sell) as sold from market group by id) as b where store.in = b.id
执行结果:
原始表store:
in | buy |
A | 1000 |
B | 2000 |
原始表market:
id | sell |
A | 100 |
A | 200 |
A | 300 |
B | 500 |
B | 400 |
SQL 语句如下:
select in, buy-sold from store, (select id, sum(sell) as sold from market group by id) as b where store.in = b.id
执行结果: