create table yyfx.ljt_1_cnt as
SELECT COUNT(CASE
WHEN B.WRITEOFF_FEE_NONCASH > (A.MONTH_FEE * 0.5) THEN
T.USER_NO
END) USER_NONCASH_50
FROM (SELECT /*+PARALLEL(T,4)*/
T.USER_NO,
T.AREA_NO,
T.AREA_NAME,
T.CITY_NO,
T.CITY_NAME,
T.CHANNEL_CLASS,
T.CHANNEL_CLASS_NAME,
T.HY_TYPE,
T.HY_TYPE_NAME,
T.PRODUCT_ID,
T.ASSURE_TYPE
FROM MID.MID_M_UE_G3_FLAG T
WHERE T.ACCT_MONTH = '201309'
AND T.USER_TYPE_CODE <> '1') T,
(SELECT PRODUCT_ID, A.MONTH_FEE, A.DINNER_TYPE_ID
FROM KPICODE.KPICODE_PRODUCT A
WHERE FLAG <> '1'
AND A.DINNER_TYPE_ID NOT IN ('0504', '0505')) A,
( SELECT /*+PARALLEL(B,4)*/
B.USER_ID,
SUM(CASE
WHEN C.DEPOSIT_TYPE_CODE IN ('0', '1') THEN
B.WRITEOFF_FEE
ELSE
0
END) WRITEOFF_FEE_CASH,
SUM(CASE
WHEN C.DEPOSIT_TYPE_CODE IN ('2', '3') THEN
B.WRITEOFF_FEE
ELSE
0
END) WRITEOFF_FEE_NONCASH
FROM (SELECT /*+PARALLEL(B,4)*/
B.USER_ID,
B.DEPOSIT_CODE,
SUM(NVL(B.WRITEOFF_FEE, 0) / 100) WRITEOFF_FEE
FROM ODSBI.TF_B_WRITEOFFLOG B
WHERE B.MONTH_ID = '201309'
AND B.NET_TYPE_CODE = '33'
GROUP BY B.USER_ID, B.DEPOSIT_CODE) B,
(SELECT DEPOSIT_CODE, C.DEPOSIT_NAME, C.DEPOSIT_TYPE_CODE
FROM STAGE.TD_B_DEPOSIT C
WHERE DEPOSIT_TYPE_CODE = '2' ---目前口径只取 2 的
AND DAY_ID = '20131103') C
WHERE B.DEPOSIT_CODE = C.DEPOSIT_CODE
GROUP BY B.USER_ID) B
WHERE T.USER_NO = B.USER_ID
AND T.PRODUCT_ID = A.PRODUCT_ID