SELECT '2022' AS year, monthNo, P.kyc, P.catg as risk_catg , 'PerTxn' as Frequency , P.breaches, 'WalletTopupTxnAmtPerTxn' as rule FROM (SELECT Z.monthNo, Z.catg, Z.kyc, SUM(IF(Z.amt > Z.limit, 1, 0)) AS breaches FROM (SELECT A.monthNo, A.senderuserid, A.transaction_id, A.amt, IF(C.hml_category IS NOT NULL, C.hml_category, 'LOW RISK') AS catg, D.kyc, CASE WHEN C.hml_category = 'HIGH RISK' AND (D.kyc = 'FULL' OR D.kyc IS NULL) THEN 10000 WHEN C.hml_category = 'MEDIUM RISK' AND (D.kyc = 'FULL' OR D.kyc IS NULL) THEN 15000 WHEN C.hml_category IS NULL AND (D.kyc = 'FULL' OR D.kyc IS NULL) THEN 20000 WHEN C.hml_category = 'HIGH RISK' AND D.kyc = 'MIN' THEN 8000 WHEN C.hml_category = 'MEDIUM RISK' AND D.kyc = 'MIN' THEN 8000 WHEN C.hml_category IS NULL AND D.kyc = 'MIN' THEN 10000 END AS limit FROM (SELECT DISTINCT senderuserid, transaction_id, month(updated_date) as monthNo, totaltransactionamount as amt from fraud.transaction_details_v3 where year(updated_date) = 2022 and month(updated_date) = 11 and sendertype = 'INTERNAL_USER' AND workflowtype = 'CONSUMER_TO_MERCHANT' and pay_transaction_status = 'COMPLETED' AND errorcode = 'SUCCESS' and receiveruser in ('PHONEPEWALLETTOPUP','NEXUSWALLETTOPUP') AND totaltransactionamount > 8000)A LEFT JOIN (SELECT DISTINCT senderuserid, hml_category FROM fraud.hml_classification)C ON A.senderuserid = C.senderuserid LEFT JOIN (SELECT DISTINCT user_ext_id, IF(kyc in ('MIN_KYC', 'MIN_KYC_V2'), 'MIN', 'FULL') as kyc FROM users.users WHERE wallet_id IS NOT NULL AND kyc in ('MIN_KYC', 'MIN_KYC_V2'))D ON A.senderuserid = D.user_ext_id)Z GROUP BY Z.catg, Z.monthNo, Z.kyc)P
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