SELECT '2022' AS year, monthNo, 'FULL' as kyc, Z.risk_catg, 'Daily' as Frequency, SUM(IF(Z.txns >= Z.limit, 1, 0)) AS breaches, 'WalletWithdrawalTxnCntDaily' as rule FROM (SELECT month(A.txnTime) AS monthNo, A.senderuserid, A.txn_id, COUNT(DISTINCT B.txn_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 as txn_id, transaction_time as txnTime FROM fraud.transaction_details_v3 WHERE year(updated_date) = 2022 AND backend_errorcode = 'SUCCESS' AND errorcode = 'SUCCESS' AND pay_transaction_status = 'COMPLETED' AND workflowtype = 'WALLET_WITHDRAWAL' AND transfermode = 'ACCOUNT_WITHDRAWAL_CLOSURE' AND wallet_flag = true)A INNER JOIN (SELECT DISTINCT senderuserid, transaction_id as txn_id, transaction_time as txnTime FROM fraud.transaction_details_v3 WHERE year(updated_date) = 2022 AND backend_errorcode = 'SUCCESS' AND errorcode = 'SUCCESS' AND pay_transaction_status = 'COMPLETED' AND workflowtype = 'WALLET_WITHDRAWAL' AND transfermode = 'ACCOUNT_WITHDRAWAL_CLOSURE' AND wallet_flag = true)B ON A.senderuserid = B.senderuserid AND A.txn_id <> B.txn_id 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 INNER JOIN (SELECT DISTINCT user_ext_id FROM users.users WHERE kyc NOT IN ('MIN_KYC', 'MIN_KYC_V2'))D ON A.senderuserid = D.user_ext_id GROUP BY month(A.txnTime), A.senderuserid, A.txn_id, C.hml_category)Z GROUP BY Z.risk_catg, Z.monthNo
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