select c.idkey,sum(c.totalMoney) from ((select b.rechargeway_idkey idkey, sum(b.payMoney) totalMoney
from mm_costMaster a left join mm_memberPaymentWay b
on a.idkey = b.costMaster_idkey
where a.chargePerson ='chaos'
and a.accountNo is null and (a.costStatus=1 or a.costStatus=3)
and a.idkey = b.costMaster_idkey
group by b.rechargeway_idkey )
UNION
(select rechargeway_idkey idkey, sum(rechargeMoney) totalMoney from mm_cardinfodetail
where accountNo is null and chargePerson ='chaos'
and rechargestatus_idkey = 1 group by rechargeway_idkey)
) c
group by c.idkey
select c.idkey,sum(c.totalMoney)
from (
(
select b.rechargeway_idkey idkey, sum(b.payMoney) totalMoney
from mm_costMaster a left join mm_memberPaymentWay b
on a.idkey = b.costMaster_idkey
where a.chargePerson ='chaos'
and a.accountNo is null and (a.costStatus=1 or a.costStatus=3)
and a.idkey = b.costMaster_idkey
group by b.rechargeway_idkey
)
UNION
(
select rechargeway_idkey idkey, sum(rechargeMoney) totalMoney from mm_cardinfodetail
where accountNo is null and chargePerson ='chaos'
and rechargestatus_idkey = 1 group by rechargeway_idkey
)
) c
group by c.idkey
今天写了300多行的代码,最后发现居然用一条sql语句就搞定了,这年头代码也太不值钱了吧!
sql真TMD的很强大,充分说明:没有做不到的,只有你想不到啊!