EGV PURCHASE TXN AMT DAILY/WEEKLY/MONTHLY

PHOTO EMBED

Mon Nov 28 2022 06:15:06 GMT+0000 (Coordinated Universal Time)

Saved by @shubhangi_burle

%jdbc(hive)
set tez.queue.name=default;
set hive.execution.engine=tez;
 
SELECT '2022' AS year, month, 'MIN + FULL' as kyc, P.risk_catg
, 'Daily' as Frequency
-- , 'Weekly' as Frequency
-- , 'Monthly' as Frequency
, P.breaches
, 'egvPurchaseTxnAmtDaily' as Rule
-- , 'egvPurchaseTxnAmtWeekly' as Rule
-- , 'egvPurchaseTxnAmtMonthly' as Rule
FROM
    (SELECT Z.risk_catg, Z.month, SUM(IF(Z.amt >= Z.limit, 1, 0)) AS breaches FROM
        (SELECT A.senderuserid, A.transaction_id, month(A.txnTime) as month, SUM(B.amt) as amt,
        IF(C.hml_category IS NOT NULL, C.hml_category, 'LOW RISK') AS risk_catg, 
        CASE WHEN C.hml_category = 'HIGH RISK' THEN 15000 WHEN C.hml_category = 'MEDIUM RISK' THEN 20000 ELSE 30000 END AS limit
        -- CASE WHEN C.hml_category = 'HIGH RISK' THEN 40000 WHEN C.hml_category = 'MEDIUM RISK' THEN 80000 ELSE 80000 END AS limit
        -- CASE WHEN C.hml_category = 'HIGH RISK' THEN 100000 WHEN C.hml_category = 'MEDIUM RISK' THEN 100000 ELSE 200000 END AS limit
        FROM
            (SELECT DISTINCT senderuserid, transaction_id, totaltransactionamount as amt, transaction_time as txnTime
            from fraud.transaction_details_v3     
            where year(updated_date) = 2022 
            and sendertype = 'INTERNAL_USER' AND workflowtype = 'CONSUMER_TO_MERCHANT'
            and pay_transaction_status = 'COMPLETED' AND errorcode = 'SUCCESS'
            and receiveruser in ('PHONEPEGC','QWIKCILVERGC')
            AND (upi_flag = 'TRUE' OR card_flag = 'TRUE'))A
        LEFT JOIN
            (SELECT DISTINCT senderuserid, transaction_id, totaltransactionamount as amt, transaction_time as txnTime
            from fraud.transaction_details_v3     
            where year(updated_date) = 2022 
            and sendertype = 'INTERNAL_USER' AND workflowtype = 'CONSUMER_TO_MERCHANT'
            and pay_transaction_status = 'COMPLETED' AND errorcode = 'SUCCESS'
            and receiveruser in ('PHONEPEGC','QWIKCILVERGC')
            AND (upi_flag = 'TRUE' OR card_flag = 'TRUE'))B
        ON A.senderuserid = B.senderuserid 
        AND ((UNIX_TIMESTAMP(A.txnTime) - UNIX_TIMESTAMP(B.txnTime))/3600) BETWEEN 0 AND 1
        -- AND ((UNIX_TIMESTAMP(A.txnTime) - UNIX_TIMESTAMP(B.txnTime))/604800) BETWEEN 0 AND 1
        -- AND ((UNIX_TIMESTAMP(A.txnTime) - UNIX_TIMESTAMP(B.txnTime))/2592000) BETWEEN 0 AND 1
        LEFT JOIN
            (SELECT DISTINCT senderuserid, hml_category FROM fraud.hml_classification)C
        ON A.senderuserid = B.senderuserid
        GROUP BY A.senderuserid, A.transaction_id, C.hml_category, month(A.txnTime))Z
    GROUP BY Z.risk_catg, month)P
content_copyCOPY