-- EXPECTED BLOCKS: RULE 9
-- LOADING OF WALLET: COUNT OF TXNS HOURLY: ROLLING
SELECT '2022' AS year, '5' as month, 'HML_DISTINCT_MERCHANT_PAYMENT_WALLET_TXN_LIMIT' as rule_name, 'LIVE' AS status, 'MIN + FULL' as kyc, P.catg, 'Hourly' as Frequency, P.breaches FROM
(SELECT Z.catg, SUM(IF(Z.txns >= Z.limit, 1, 0)) AS breaches FROM
(SELECT A.senderuserid, A.day, 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 2 WHEN C.hml_category = 'MEDIUM RISK' THEN 3 ELSE 5 END AS limit FROM
(SELECT DISTINCT senderuserid, Day(updated_date) as day, transaction_id, updated_date AS txnTime
from fraud.transaction_details
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, Day(updated_date) as day, transaction_id, updated_date AS txnTime
from fraud.transaction_details
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'))B
ON A.senderuserid = B.senderuserid AND ((UNIX_TIMESTAMP(A.txnTime) - UNIX_TIMESTAMP(B.txnTime))/3600) 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.day, A.transaction_id, C.hml_category)Z
GROUP BY Z.catg)P
Comments