马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
SELECT
subq.groupname,
--subq.members,
--subq.billno,
--subq.optime,
subq.node,
subq.cop,
subq.brand,
--subq.billtype,
--subq.billstyle,
subq.num_bill,
subq.times_ssc_approve,
subq.times_ssc_reject,
subq.times_ssc_cancel,
round(subq.times_ssc_approve + subq.times_ssc_reject - subq.times_ssc_cancel, 0) AS times_ssc_final,
CASE
WHEN subq.times_ssc_reject = 0 THEN NULL
ELSE round((subq.times_ssc_reject / subq.num_bill) * 100, 2)
END AS reject_percentage,
subq.times_bus_reject
FROM
(
SELECT
d.name AS groupname,
--a.billno billno,
--us.user_name AS members,
--SUBSTR(a.operatetime,0,10) AS optime,
sn.name AS node,
org.shortname as cop,
ad2.name AS brand,
--c.BILLTYPENAME as billtype,
--c.parentbilltype as billstyle,
COUNT(DISTINCT CASE WHEN (a.actiontype = 'sscapprove' OR (a.actiontype = 'sscreject' AND a.BEGINSTATE <> 'sscapprove')) THEN a.billno END) AS num_bill,
COUNT(CASE WHEN a.actiontype = 'sscapprove' THEN a.billno END) AS times_ssc_approve,
COUNT(CASE WHEN (a.actiontype = 'sscreject' AND a.BEGINSTATE <> 'sscapprove') THEN a.billno END) AS times_ssc_reject,
COUNT(CASE WHEN (a.actiontype = 'un-sscapprove' AND a.BEGINSTATE <> 'notake') THEN a.billno END) AS times_ssc_cancel,
COUNT(CASE WHEN (a.actiontype = 'sscreject' AND a.BEGINSTATE = 'sscapprove') THEN a.billno END) AS times_bus_reject
FROM
ncc.ssctp_flowpath a
LEFT JOIN ncc.bd_billtype c ON
c.pk_billtypeid = a.pk_tradetype
LEFT JOIN ncc.ssctp_workinggroup d ON
d.pk_workinggroup = a.pk_sscgroup
LEFT JOIN ncc.org_orgs org ON
org.pk_org = a.pk_org
LEFT JOIN org_adminorg ad ON
ad.name = org.name
LEFT JOIN org_adminorg ad2 ON
ad2.pk_adminorg = ad.pk_fatherorg
LEFT JOIN ncc.sm_user us ON
us.cuserid = a.operater
LEFT JOIN ncc.ssctp_node sn ON
sn.pk_sscnode = a.pk_sscnode
WHERE
a.operatetime >= '2024-01-01 00:00:00'
AND a.operatetime <= '2024-08-31 23:59:59'
AND org.name <> '虚拟店'
--AND org.name = '杭州和诚之宝汽车销售服务有限公司'
--AND org.def12 = '商用车品线'
AND d.name = '费用核算组'
AND c.billtypename IN ('差旅费用报销单','业务招待费用报销单')
GROUP BY
d.name,
--a.billno,
--us.user_name,
sn.name,
--SUBSTR(a.operatetime,0,10)
--sn.name
org.shortname,
ad2.name ) subq
--c.BILLTYPENAME
--c.parentbilltype
WHERE
num_bill <> 0
OR times_ssc_reject <> 0;
|