SELECT sum(a.balance*10000), c.balance_type_id
FROM cashbill@infoserver_147:BALANCE_ACCT_ITEM_PAYED_947 a,
cashbill@infoserver_147:BALANCE_PAYOUT_947 b,
cashbill@infoserver_147:ACCT_BALANCE c,
cashbill@infoserver_147:BALANCE_TYPE d
where 1=1
and a.acct_item_id in(200096470102,399996470102,304293354211)
and a.oper_payout_id = b.oper_payout_id
and b.state = '00A'
and b.oper_type = '5UJ'
and b.acct_balance_id = c.acct_balance_id
and c. balance_type_id = d.balance_type_id
and d.inv_offer = '5BB'
group by c.balance_type_id ;
比如这个SQL查询,a,b,c,d都是大表,现在需要优化,把联合查询拆分开,通过几次单表查询,在程序里组装出查询结果。有什么好的方法吗?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…