我有许多表,我从中获取数据我获取的数据是正确的,但只是收集的数量。
但现在我想得到总剩余金额和总未付金额地区明智的。
要清楚,总未付金额是在回收表
收集的金额在投诉行动表中。
我的要求是,我必须在不同的日期显示个人收款金额,并按地区显示收款总额、剩余总额和未付总额:
下面是我想展示结果的图片:
查询获取以下数据
select sum(y.salab1) salab1,sum(y.salab2) salab2,sum(y.salab3)
salab3,sum(y.salab4) salab4,sum(y.salab5) salab5,sum(y.salab6)
salab6,y.regionName,y.zonName from (
select
(CASE
WHEN (CEIL((DATEDIFF(CURRENT_TIMESTAMP(), rcv.`AGING_DATE`) /15)) = 1 ) THEN
sum( IFNULL(cpa.`COLLECTED_AMOUNT`, 0) )
ELSE 0
END) as salab1,
(CASE
WHEN (CEIL((DATEDIFF(CURRENT_TIMESTAMP(), rcv.`AGING_DATE`) /15)) = 2 )
THEN sum(IFNULL(cpa.`COLLECTED_AMOUNT`, 0) )
ELSE 0
END) as salab2,
(CASE
WHEN (CEIL((DATEDIFF(CURRENT_TIMESTAMP(), rcv.`AGING_DATE`) /15)) = 3 ) THEN
sum(IFNULL(cpa.`COLLECTED_AMOUNT`, 0) )
ELSE 0
END) as salab3,
(CASE
WHEN (CEIL((DATEDIFF(CURRENT_TIMESTAMP(), rcv.`AGING_DATE`) /15)) = 4 )
THEN sum(IFNULL(cpa.`COLLECTED_AMOUNT`, 0) )
ELSE 0
END) as salab4,
(CASE
WHEN (CEIL((DATEDIFF(CURRENT_TIMESTAMP(), rcv.`AGING_DATE`) /15)) = 5 ) THEN
sum(IFNULL(cpa.`COLLECTED_AMOUNT`, 0) )
ELSE 0
END) as salab5,
(CASE
WHEN (CEIL((DATEDIFF(CURRENT_TIMESTAMP(), rcv.`AGING_DATE`) /15)) >5 )
THEN sum( IFNULL(cpa.`COLLECTED_AMOUNT`, 0) )
ELSE 0
END) as salab6,
CEIL((DATEDIFF(CURRENT_TIMESTAMP(), rcv.`AGING_DATE`) /15)) as slab
, rgn.`NAME` as regionName, zn.`NAME` as zonName,rcv.AMOUNT
from `recovery` rcv
join complain cmp on cmp.`CODE` = rcv.`COMPLAINT_ID`
join customerprofile cp on cp.`REG_CODE` = cmp.`CUST_REG_NO`
join marketofficer mo on mo.`MO_ID` = rcv.`RO_ID`
LEFT OUTER join complain_actions cpa on cpa.`COMPLAIN_CODE` = cmp.`CODE`
join market mrkt on mrkt.`ID` = cp.`MARKET_ID`
join area ar on ar.`ID` = mrkt.`AREA_ID`
join city cty on cty.`ID` = ar.`CITY_ID`
join region rgn on rgn.`ID` = cty.`REGION_ID`
join `zone` zn on zn.`ID` = rgn.`ZONE_ID`
group by zonName,regionName,slab) y group by y.zonName,y.regionName
此查询正在获取按区域和区域收集的金额,但我要全部
收款天数
收款总额
总剩余金额
未偿总额
谢谢。
暂无答案!
目前还没有任何答案,快来回答吧!