测试如下的代码!
select A.CITYNAME,
sum(A.MonthRechargeCount) MonthRechargeCount,
sum(B.MONTHREVERSALCOUNT) MONTHREVERSALCOUNT,
sum(round(A.MonthRechargeCount * 0.0025)) NORMALTRAVERSALRATE,
sum((round(A.MonthRechargeCount * 0.0025) - B.MONTHREVERSALCOUNT)) MONTHREVERSALCONTRAST
from (select cust.cityname,
sum(sm.sumcount) MonthRechargeCount,
'2.5' NormalTreversalRate
from everydaysummoney sm, stkcard stk, customer cust, dataRight dr
where sm.orgaddr = stk.stkaddr
and stk.custID = cust.ID
and cust.cityname = dr.rightname
and sm.applytime >= TRUNC(sysdate, 'mm')
and sm.applytime < TRUNC(sysdate)
group by cust.cityname) A
left join (select CUST.CITYNAME, count(*) MONTHREVERSALCOUNT
from treversal_all ta,
stkcard stk,
customer cust,
dataRight dr
where ta.ORGADDR = stk.stkaddr
and stk.custid = cust.id
and cust.cityname = dr.rightname
and ta.applytime >= trunc(sysdate, 'mm')
and ta.applytime < trunc(sysdate)
and ta.reversalstate = 0
group by CUST.CITYNAME) B on A.CITYNAME = B.CITYNAME
group by grouping sets(A.CITYNAME,());