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的很强大,充分说明:没有做不到的,只有你想不到啊!

相关文章:

  • 2021-06-23
  • 2021-04-29
  • 2021-10-21
  • 2021-08-03
  • 2021-10-12
  • 2022-12-23
猜你喜欢
  • 2021-06-20
  • 2021-04-22
  • 2021-10-25
  • 2021-10-06
  • 2021-08-07
  • 2021-09-25
  • 2022-12-23
相关资源
相似解决方案