SELECT '2022' AS year, monthNo, kyc, catg AS risk_catg, 'Monthly' as Frequency, SUM(IF(totAmt > IF(kyc = 'MIN', (10000 * 0.02), (100000 * 0.02)), 1, 0)) as breaches , 'WalletTopupTxnAmtMonthly' as rule FROM (SELECT A.monthNo, IF(C.hml_category IS NOT NULL, C.hml_category, 'LOW RISK') AS catg, D.kyc, A.transaction_id, (A.amt + SUM(B.amt)) as totAmt FROM (SELECT DISTINCT senderuserid, transaction_id, month(updated_date) as monthNo, totaltransactionamount as amt, transaction_time as TxnTime 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'))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 month(updated_date) IN (11-1, 11) 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))/2592000) BETWEEN 0 AND 1 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 GROUP BY A.monthNo, C.hml_category, D.kyc, A.transaction_id, A.amt)P GROUP BY monthNo, kyc, catg
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