首页区间筛选调整
This commit is contained in:
parent
d7bf8b08ea
commit
398d45ee49
@ -213,14 +213,14 @@ AND exists (
|
|||||||
-- 年
|
-- 年
|
||||||
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
|
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
|
||||||
-- 季
|
-- 季
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(sStart_date,4),roundup(month(sStart_date)/3)) +"'","")}
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
-- 月
|
-- 月
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_date,'yyyy-MM') +"'","")}
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
-- 日
|
-- 日
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ sStart_date +"'","")}
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
select
|
select
|
||||||
@ -248,14 +248,15 @@ where (indi_type='回款' OR indi_type='电商订单')
|
|||||||
-- 去年
|
-- 去年
|
||||||
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') = '" + left(yeardelta(sStart_date,-1),4) + "'","")}
|
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') = '" + left(yeardelta(sStart_date,-1),4) + "'","")}
|
||||||
-- 去年同季
|
-- 去年同季
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ yeardelta(sStart_date,-1) +"'","")}
|
${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(YEARDELTA(sStart_date,-1),4),roundup(month(YEARDELTA(sStart_date,-1))/3)) +"'","")}
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
|
||||||
|
-- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
||||||
-- 去年同月
|
-- 去年同月
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ yeardelta(sStart_date,-1) +"'","")}
|
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM') +"'","")}
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
-- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
||||||
-- 去年同日
|
-- 去年同日
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ yeardelta(sStart_date,-1) +"'","")}
|
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ yeardelta(sStart_date,-1) +"'","")}
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
-- ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
||||||
UNION
|
UNION
|
||||||
select
|
select
|
||||||
'目标' time_type,
|
'目标' time_type,
|
||||||
@ -285,14 +286,15 @@ AND exists (
|
|||||||
-- 年
|
-- 年
|
||||||
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
|
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
|
||||||
-- 季
|
-- 季
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(sStart_date,4),roundup(month(sStart_date)/3)) +"'","")}
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
-- 月
|
-- 月
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_date,'yyyy-MM') +"'","")}
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
-- 日
|
-- 日
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ sStart_date +"'","")}
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
|
||||||
|
-- ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
|
|
||||||
-- ======================================
|
-- ======================================
|
||||||
-- 经销商出货
|
-- 经销商出货
|
||||||
@ -323,14 +325,14 @@ where (indi_type='出货' OR indi_type='电商订单')
|
|||||||
-- 年
|
-- 年
|
||||||
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
|
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
|
||||||
-- 季
|
-- 季
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(sStart_date,4),roundup(month(sStart_date)/3)) +"'","")}
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
-- 月
|
-- 月
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_date,'yyyy-MM') +"'","")}
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
-- 日
|
-- 日
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ sStart_date +"'","")}
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
select
|
select
|
||||||
@ -358,14 +360,14 @@ where (indi_type='出货' OR indi_type='电商订单')
|
|||||||
-- 去年
|
-- 去年
|
||||||
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') = '" + left(yeardelta(sStart_date,-1),4) + "'","")}
|
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') = '" + left(yeardelta(sStart_date,-1),4) + "'","")}
|
||||||
-- 去年同季
|
-- 去年同季
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ yeardelta(sStart_date,-1) +"'","")}
|
${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(YEARDELTA(sStart_date,-1),4),roundup(month(YEARDELTA(sStart_date,-1))/3)) +"'","")}
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
-- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
||||||
-- 去年同月
|
-- 去年同月
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ yeardelta(sStart_date,-1) +"'","")}
|
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM') +"'","")}
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
-- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
||||||
-- 去年同日
|
-- 去年同日
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ yeardelta(sStart_date,-1) +"'","")}
|
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ yeardelta(sStart_date,-1) +"'","")}
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
-- ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
||||||
|
|
||||||
|
|
||||||
UNION
|
UNION
|
||||||
@ -398,14 +400,14 @@ where ${switch(sPeriod
|
|||||||
-- 年
|
-- 年
|
||||||
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
|
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
|
||||||
-- 季
|
-- 季
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(sStart_date,4),roundup(month(sStart_date)/3)) +"'","")}
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
-- 月
|
-- 月
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_date,'yyyy-MM') +"'","")}
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
-- 日
|
-- 日
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ sStart_date +"'","")}
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
|
|
||||||
|
|
||||||
-- ======================================
|
-- ======================================
|
||||||
@ -437,14 +439,14 @@ where (indi_type='发货' OR indi_type='费用发货')
|
|||||||
-- 年
|
-- 年
|
||||||
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
|
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
|
||||||
-- 季
|
-- 季
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(sStart_date,4),roundup(month(sStart_date)/3)) +"'","")}
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
-- 月
|
-- 月
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_date,'yyyy-MM') +"'","")}
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
-- 日
|
-- 日
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ sStart_date +"'","")}
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
UNION ALL
|
UNION ALL
|
||||||
select
|
select
|
||||||
'同期' time_type
|
'同期' time_type
|
||||||
@ -471,14 +473,14 @@ where (indi_type='发货' OR indi_type='费用发货')
|
|||||||
-- 去年
|
-- 去年
|
||||||
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') = '" + left(yeardelta(sStart_date,-1),4) + "'","")}
|
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') = '" + left(yeardelta(sStart_date,-1),4) + "'","")}
|
||||||
-- 去年同季
|
-- 去年同季
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ yeardelta(sStart_date,-1) +"'","")}
|
${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(YEARDELTA(sStart_date,-1),4),roundup(month(YEARDELTA(sStart_date,-1))/3)) +"'","")}
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
-- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
||||||
-- 去年同月
|
-- 去年同月
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ yeardelta(sStart_date,-1) +"'","")}
|
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM') +"'","")}
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
-- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
||||||
-- 去年同日
|
-- 去年同日
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ yeardelta(sStart_date,-1) +"'","")}
|
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ yeardelta(sStart_date,-1) +"'","")}
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
-- ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
|
||||||
|
|
||||||
|
|
||||||
UNION
|
UNION
|
||||||
@ -510,14 +512,14 @@ where ${switch(sPeriod
|
|||||||
-- 年
|
-- 年
|
||||||
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
|
${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
|
||||||
-- 季
|
-- 季
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(sStart_date,4),roundup(month(sStart_date)/3)) +"'","")}
|
||||||
${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
-- 月
|
-- 月
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_date,'yyyy-MM') +"'","")}
|
||||||
${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
-- 日
|
-- 日
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
|
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ sStart_date +"'","")}
|
||||||
${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
-- ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
|
||||||
|
|
||||||
|
|
||||||
-- ======================================
|
-- ======================================
|
||||||
@ -757,39 +759,29 @@ where corp_code not in ('0101','0103','0102')
|
|||||||
-- 财务资金月度
|
-- 财务资金月度
|
||||||
-- ======================================
|
-- ======================================
|
||||||
|
|
||||||
|
|
||||||
;
|
|
||||||
-- 资金计划与执行
|
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
t.stat_date AS stat_date
|
t.stat_date AS stat_date
|
||||||
,to_char(t.stat_date,'MM') as month
|
,to_char(t.stat_date,'MM') as month
|
||||||
,CASE WHEN t.fee_type = '收入' THEN amt ELSE 0 END AS revenue_fee -- 收入
|
,CASE WHEN t.fee_type = '收入' THEN amt ELSE 0 END AS revenue_fee -- 收入
|
||||||
,CASE WHEN t.fee_type = '支出' THEN amt ELSE 0 END AS expend_fee -- 支出
|
,CASE WHEN t.fee_type = '支出' THEN amt ELSE 0 END AS expend_fee -- 支出
|
||||||
,CASE WHEN t.fee_type = '余额' THEN amt ELSE 0 END AS balance_fee -- 余额
|
,CASE WHEN t.fee_type = '余额' THEN amt ELSE 0 END AS balance_fee -- 余额
|
||||||
|
FROM (SELECT stat_date
|
||||||
FROM
|
|
||||||
(
|
|
||||||
select
|
|
||||||
stat_date
|
|
||||||
, '收入' AS fee_type -- 收支方向 收入/支出
|
, '收入' AS fee_type -- 收支方向 收入/支出
|
||||||
, SUM(CASE WHEN trade_direction = '收入' THEN amt ELSE 0 END) / 10000 AS amt
|
, SUM(CASE WHEN trade_direction = '收入' THEN amt ELSE 0 END) / 10000 AS amt
|
||||||
from dm.dm_fim_fud_indicator a
|
FROM dm.dm_fim_fud_indicator a
|
||||||
where corp_code not in ('0101','0103','0102')
|
WHERE corp_code NOT IN ('0101', '0103', '0102')
|
||||||
AND trade_direction = '收入'
|
AND trade_direction = '收入'
|
||||||
AND indi_type = '执行'
|
AND indi_type = '执行'
|
||||||
AND plan_item_name NOT IN ('内部调拨收入', '取得贷款')
|
AND plan_item_name NOT IN ('内部调拨收入', '取得贷款')
|
||||||
AND owner_bank_account <> '22195101040012008'
|
AND owner_bank_account <> '22195101040012008'
|
||||||
-- 权限控制
|
-- 权限控制
|
||||||
AND exists (
|
AND exists(select 1
|
||||||
select
|
FROM
|
||||||
1
|
|
||||||
from
|
|
||||||
dm.dm_bi_user_permisson
|
dm.dm_bi_user_permisson
|
||||||
where
|
WHERE
|
||||||
bi_user = '${fine_username}'
|
bi_user = '${fine_username}'
|
||||||
and per_model IN ('all','sal')
|
AND per_model IN ('all','sal')
|
||||||
and (
|
AND (
|
||||||
is_all = 1
|
is_all = 1
|
||||||
OR per_code = a.corp_code -- 事业部
|
OR per_code = a.corp_code -- 事业部
|
||||||
-- OR per_code = a.region_code -- 大区
|
-- OR per_code = a.region_code -- 大区
|
||||||
@ -805,28 +797,25 @@ FROM
|
|||||||
-- 日
|
-- 日
|
||||||
-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >= '"+ sStart_date_fin +"'","")}
|
-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >= '"+ sStart_date_fin +"'","")}
|
||||||
-- ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ sStart_date_fin +"'","")}
|
-- ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ sStart_date_fin +"'","")}
|
||||||
group by stat_date
|
GROUP BY stat_date
|
||||||
UNION ALL
|
UNION ALL
|
||||||
select
|
SELECT stat_date
|
||||||
stat_date
|
|
||||||
, '支出' AS fee_type -- 收支方向 收入/支出
|
, '支出' AS fee_type -- 收支方向 收入/支出
|
||||||
, SUM(CASE WHEN trade_direction = '支出' THEN amt ELSE 0 END) / 10000 AS amt
|
, SUM(CASE WHEN trade_direction = '支出' THEN amt ELSE 0 END) / 10000 AS amt
|
||||||
from dm.dm_fim_fud_indicator a
|
FROM dm.dm_fim_fud_indicator a
|
||||||
where corp_code not in ('0101','0103','0102')
|
WHERE corp_code NOT IN ('0101', '0103', '0102')
|
||||||
AND trade_direction = '支出'
|
AND trade_direction = '支出'
|
||||||
AND indi_type = '执行'
|
AND indi_type = '执行'
|
||||||
AND plan_item_name NOT IN ('内部调拨支出', '偿还贷款')
|
AND plan_item_name NOT IN ('内部调拨支出', '偿还贷款')
|
||||||
AND owner_bank_account <> '22195101040012008'
|
AND owner_bank_account <> '22195101040012008'
|
||||||
-- 权限控制
|
-- 权限控制
|
||||||
AND exists (
|
AND exists(select 1
|
||||||
select
|
FROM
|
||||||
1
|
|
||||||
from
|
|
||||||
dm.dm_bi_user_permisson
|
dm.dm_bi_user_permisson
|
||||||
where
|
WHERE
|
||||||
bi_user = '${fine_username}'
|
bi_user = '${fine_username}'
|
||||||
and per_model IN ('all','sal')
|
AND per_model IN ('all','sal')
|
||||||
and (
|
AND (
|
||||||
is_all = 1
|
is_all = 1
|
||||||
OR per_code = a.corp_code -- 事业部
|
OR per_code = a.corp_code -- 事业部
|
||||||
-- OR per_code = a.region_code -- 大区
|
-- OR per_code = a.region_code -- 大区
|
||||||
@ -842,42 +831,62 @@ FROM
|
|||||||
-- 日
|
-- 日
|
||||||
-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date_fin +"'","")}
|
-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date_fin +"'","")}
|
||||||
-- ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sStart_date_fin +"'","")}
|
-- ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sStart_date_fin +"'","")}
|
||||||
group by stat_date
|
GROUP BY stat_date
|
||||||
UNION ALL
|
UNION ALL
|
||||||
-- 月初资金余额要取上月的月初的,年初要取上年末12月份的
|
-- 月初资金余额要取上月的月初的,年初要取上年末12月份的
|
||||||
select
|
|
||||||
stat_date AS stat_date
|
SELECT
|
||||||
|
A.stat_date AS stat_date
|
||||||
, '余额' AS fee_type
|
, '余额' AS fee_type
|
||||||
,sum(amt) / 10000 AS AMT
|
,SUM(B.amt) / 10000 AS AMT
|
||||||
from dm.dm_fim_fud_balance a
|
FROM
|
||||||
where corp_code not in ('0101','0103','0102')
|
(
|
||||||
AND owner_bank_account NOT IN ('20351059900100000512291'
|
SELECT
|
||||||
,'22195101040012008'
|
stat_date
|
||||||
,'信用证保证金'
|
,stat_date - INTERVAL '1 month' AS stat_date1
|
||||||
,'22195162750000012'
|
, SUM(amt) / 10000 AS AMT
|
||||||
,'22195162650000017'
|
FROM dm.dm_fim_fud_balance a
|
||||||
,'22195162350000014'
|
WHERE corp_code NOT IN ('0101', '0103', '0102')
|
||||||
,'22195162050000015'
|
AND owner_bank_account NOT IN
|
||||||
,'951018033000447470')
|
('20351059900100000512291', '22195101040012008', '信用证保证金', '22195162750000012', '22195162650000017',
|
||||||
|
'22195162350000014', '22195162050000015', '951018033000447470')
|
||||||
-- 权限控制
|
-- 权限控制
|
||||||
AND exists (
|
AND EXISTS (SELECT 1
|
||||||
select
|
FROM dm.dm_bi_user_permisson
|
||||||
1
|
WHERE bi_user = '${fine_username}'
|
||||||
from
|
AND per_model IN ('all', 'sal')
|
||||||
dm.dm_bi_user_permisson
|
AND (
|
||||||
where
|
|
||||||
bi_user = '${fine_username}'
|
|
||||||
and per_model IN ('all','sal')
|
|
||||||
and (
|
|
||||||
is_all = 1
|
is_all = 1
|
||||||
OR per_code = a.corp_code -- 事业部
|
OR per_code = a.corp_code -- 事业部
|
||||||
-- OR per_code = a.region_code -- 大区
|
-- OR per_code = a.region_code -- 大区
|
||||||
-- OR per_code = a.office_code -- 办事处
|
-- OR per_code = a.office_code -- 办事处
|
||||||
-- OR per_code = a.city_unit_code -- 城市单元
|
-- OR per_code = a.city_unit_code -- 城市单元
|
||||||
)
|
))
|
||||||
)
|
GROUP BY stat_date - INTERVAL '1 month',stat_date
|
||||||
|
)A
|
||||||
|
LEFT JOIN
|
||||||
|
(
|
||||||
|
SELECT stat_date AS stat_date
|
||||||
|
|
||||||
${IF(len(sStart_date_fin) > 0,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")}
|
, SUM(amt) / 10000 AS AMT
|
||||||
|
FROM dm.dm_fim_fud_balance a
|
||||||
|
WHERE corp_code NOT IN ('0101', '0103', '0102')
|
||||||
|
AND owner_bank_account NOT IN
|
||||||
|
('20351059900100000512291', '22195101040012008', '信用证保证金', '22195162750000012', '22195162650000017',
|
||||||
|
'22195162350000014', '22195162050000015', '951018033000447470')
|
||||||
|
-- 权限控制
|
||||||
|
AND EXISTS (SELECT 1
|
||||||
|
FROM dm.dm_bi_user_permisson
|
||||||
|
WHERE bi_user = '${fine_username}'
|
||||||
|
AND per_model IN ('all', 'sal')
|
||||||
|
AND (
|
||||||
|
is_all = 1
|
||||||
|
OR per_code = a.corp_code -- 事业部
|
||||||
|
))
|
||||||
|
GROUP BY stat_date
|
||||||
|
)B
|
||||||
|
ON A.stat_date1 = B.stat_date
|
||||||
|
${IF(len(sStart_date_fin) > 0,"AND to_char(a.stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")}
|
||||||
|
|
||||||
|
|
||||||
-- 年
|
-- 年
|
||||||
@ -887,6 +896,6 @@ FROM
|
|||||||
-- 日
|
-- 日
|
||||||
-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date_fin +"'","")}
|
-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date_fin +"'","")}
|
||||||
-- ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sStart_date_fin +"'","")}
|
-- ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sStart_date_fin +"'","")}
|
||||||
group by stat_date
|
group by A.stat_date
|
||||||
)t
|
)t
|
||||||
ORDER BY to_char(t.stat_date,'MM')
|
ORDER BY to_char(t.stat_date,'MM')
|
Loading…
Reference in New Issue
Block a user