我有一个有效的查询,不确定它是否有效。
表列:
- p_type: 可以是 STRING sell、cancelsell、bank、cancelbank
- ID
- 菲德
- 单元
要执行的操作:
- 每种流程类型的 SUM(单位)sell、cancelsell、bank、cancelbank。
- SUM(UNIT for sell) - SUM(unit for cancelsell) , SUM(unit for bank) - SUM(unit for cancelbank)
注意:虽然我需要检查所有选择的相同值,但我也在检查每个选择中的 id 和 fid。
现有查询:
select sell-cancelsell scount, bank-cancelbank bcount from
(select sum(a.unit) as sell from table1 a where
a.p_type = 'Sell' and a.id=1 and a.fid=2 ),
(select sum(c.unit) as cancelsell from table1 c where
c.p_type = 'CancelSell' and c.id=1 and c.fid=2),
(select sum(b.unit) as bank from table1 b where
b.p_type = 'Bank' and b.id=1 and b.fid=2),
(select sum(d.unit) as cancelbank from table1 d where
d.p_type = 'CancelBank' and d.id=1 and d.fid=2)
够好吗?如果有人可以提出一种提高效率的方法,那就太好了。