-- 86400 for daily 'WalletTopupTxnCntDaily' -- 3600 for hourly 'WalletTopupTxnCntHourly' -- 2592000 for monthly 'WalletTopupTxnCntMonthly' SELECT '2022' AS year, monthNo, 'MIN + FULL' as kyc, risk_catg, 'Daily' as Frequency, Z.transaction_id, 'WalletTopupTxnCntDaily' as rule 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 risk_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 WHERE Z.txns >= Z.limit
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter