RULE 14 DAILY

PHOTO EMBED

Wed Jul 06 2022 12:02:25 GMT+0000 (Coordinated Universal Time)

Saved by @shubhangi_burle

-- EXPECTED BLOCKS: RULE 14
-- LOADING OF WALLET: COUNT OF TXNS DAILY: ROLLING
SELECT '2022' AS year, monthNo, 'MIN + FULL' as kyc, P.catg as risk_catg, 'Hourly' as Frequency, P.breaches FROM
    (SELECT Z.monthNo, Z.catg, SUM(IF(Z.txns >= Z.limit, 1, 0)) AS breaches FROM
        (SELECT A.monthNo, A.senderuserid, A.transaction_id, COUNT(DISTINCT B.transaction_id) as txns, 
        IF(C.hml_category IS NOT NULL, C.hml_category, 'LOW RISK') AS catg,
        CASE WHEN C.hml_category = 'HIGH RISK' THEN 5 WHEN C.hml_category = 'MEDIUM RISK' THEN 8 ELSE 10 END AS limit FROM
            (SELECT DISTINCT senderuserid, transaction_id, transaction_time AS txnTime, month(updated_date) as monthNo
            from fraud.transaction_details_v3     
            where year(updated_date) = 2022 -- and month(updated_date) = 5
            and sendertype = 'INTERNAL_USER' AND workflowtype = 'CONSUMER_TO_MERCHANT'
            and pay_transaction_status = 'COMPLETED' AND errorcode = 'SUCCESS'
            and receiveruser in ('PHONEPEWALLETTOPUP','NEXUSWALLETTOPUP'))A
        LEFT JOIN
            (SELECT DISTINCT senderuserid, transaction_id, transaction_time AS txnTime, month(updated_date) as monthNo
            from fraud.transaction_details_v3     
            where year(updated_date) = 2022 -- and month(updated_date) IN (4,5)
            and sendertype = 'INTERNAL_USER' AND workflowtype = 'CONSUMER_TO_MERCHANT'
            and pay_transaction_status = 'COMPLETED' AND errorcode = 'SUCCESS'
            and receiveruser in ('PHONEPEWALLETTOPUP','NEXUSWALLETTOPUP'))B
        ON A.senderuserid = B.senderuserid AND A.monthNo >= B.monthNo
        AND ((UNIX_TIMESTAMP(A.txnTime) - UNIX_TIMESTAMP(B.txnTime))/86400) BETWEEN 0 AND 1 AND A.txnTime > B.txnTime
        LEFT JOIN
            (SELECT DISTINCT senderuserid, hml_category
            FROM fraud.hml_classification)C
        ON A.senderuserid = C.senderuserid
        GROUP BY A.senderuserid, A.transaction_id, C.hml_category, A.monthNo
        HAVING txns >= 5)Z
    GROUP BY Z.catg, Z.monthNo)P
content_copyCOPY