Chatbot Data

PHOTO EMBED

May 29 2025

Saved by @Shivam3.tyagi

  1. select pg.mid,
  2. pg.Month,
  3. CASE
  4. WHEN m_3.o_mid IS NOT NULL THEN 'Online'
  5. WHEN m_4.e_mid IS NOT NULL THEN 'EDC'
  6. ELSE 'QR'
  7. END AS EDC_QR,
  8. m_7.channel as subBusiness,
  9. mcc.mcc as mccCode,
  10. pg.category,
  11. pg.subCategory,
  12. sum(pg.attemptedGMV)as attemptedGMV,
  13. sum(pg.seccessfulGMV) asseccessfulGMV ,
  14. sum(pg.refundGMV) refundGMV,
  15. sum(rej.rejectedGMV)rejectedGMV ,
  16. sum(pg.failedGMV) failedGMV,
  17. sum(frd.fraudGMV) fraudGMV,
  18. sum(cb.cbGMV) cbGMV
  19. from
  20. (SELECT mid, month(txn_started_at) as Month,category,sub_category subCategory,
  21. sum(txn_amount) as attemptedGMV, sum(Case when txn_status = 'SUCCESS' then txn_amount else 0 end) as seccessfulGMV,
  22. sum(Case when txn_status <> 'SUCCESS' then txn_amount else 0 end) as failedGMV,
  23. sum(case when txn_status = 'SUCCESS' and refund_amount is not null and refund_amount > 0 then txn_amount end) as refundGMV
  24. FROM
  25. dwh.pg_olap
  26. WHERE category NOT IN ('OnPaytm', 'Test')
  27. AND mid IS NOT NULL
  28. AND txn_amount > 0
  29. AND txn_id IS NOT NULL
  30. AND ingest_date >= date '2024-10-01'
  31. AND DATE (substr(cast(txn_started_at AS VARCHAR), 1, 10)) between date '2024-10-01' and date '2025-02-28'
  32. group by 1,2,3,4) as pg
  33.  
  34. -- Mapping QR/EDC mids
  35. LEFT JOIN (
  36. SELECT DISTINCT merchant_id AS o_mid
  37. FROM datalake.online_payment_merchants
  38. ) AS m_3
  39. ON pg.mid = m_3.o_mid
  40. LEFT JOIN (
  41. SELECT DISTINCT
  42. mid AS e_mid
  43. FROM
  44. paytmpgdb.entity_edc_info_snapshot_v3
  45. WHERE
  46. terminal_status = 'ACTIVE'
  47. AND dl_last_updated >= DATE '2010-01-01'
  48. ) m_4 ON pg.mid = m_4.e_mid
  49.  
  50. -- Mapping Channel here
  51. LEFT Join (
  52. select distinct
  53. pg_mid,
  54. channel
  55. from
  56. cdo.total_offline_merchant_base_snapshot_v3
  57. ) AS m_7 ON pg.mid = m_7.pg_mid
  58. left join
  59. (SELECT distinct upi_mcc_code mcc,
  60. category ,
  61. sub_category
  62. FROM paytmpgdb.mcc_code_mapping_snapshot_v3) mcc
  63. on pg.category = mcc.category and pg.subCategory = mcc.sub_category
  64.  
  65. -- Mapping rejected GMV
  66. left join
  67. (select mid,month(dateinserted) as Month,
  68. sum(txn_amount) rejectedGMV
  69. from (
  70. select
  71. transactionid,
  72. max(dateinserted) dateinserted ,
  73. max(cast(eventamount as double)/100) txn_amount ,
  74. max(paytmmerchantid) mid
  75. from
  76. cdp_risk_transform.maquette_flattened_offus_snapshot_v3
  77. where
  78. dl_last_updated >= date'2024-10-01'
  79. and DATE (dateinserted) between date '2024-10-01' and date '2025-02-28'
  80. AND actionrecommended = 'BLOCK'
  81. group by 1)
  82. group by 1,2) as rej ON pg.mid = rej.mid and pg.Month=rej.Month
  83.  
  84. -- Mapping fraudGMV
  85. left join
  86. (select mid,month(txn_date) as Month,
  87. sum(txn_amount) fraudGMV
  88. from
  89. (select
  90. old_pg_txn_id as txn_id,
  91. min(cast(old_pg_txn_amount as double)) txn_amount,
  92. min(date(old_pg_txn_started_at)) txn_date,
  93. min(old_pg_ingest_date) old_pg_ingest_date,
  94. min(old_pg_mid) mid
  95. from
  96. frauds.fraud_combined_snapshot_v3
  97. where
  98. dl_last_updated >= date'2024-10-01'
  99. and DATE (old_pg_txn_started_at) between date '2024-10-01' and date '2025-02-28'
  100. and table_name in (
  101. 'ppsl_cybercell',
  102. 'ro_panel_cybmerchant_details_with_pg_olap',
  103. 'lending_fraud',
  104. 'efrm',
  105. 'ppsl_bank_escalations',
  106. 'ro_panel_minifmr_l2_PPI',
  107. 'ro_panel_minifmr_l2_BNK'
  108. )
  109. and old_pg_category NOT IN ('OnPaytm', 'Test')
  110. and old_pg_txn_status = 'SUCCESS'
  111. AND old_pg_mid IS NOT NULL
  112. AND cast(old_pg_txn_amount as double) > 0
  113. AND old_pg_txn_id IS NOT NULL
  114. group by 1)
  115. group by 1,2) as frd on pg.mid=frd.mid and pg.Month=frd.Month
  116. -- Mapping chargeBack
  117. left join (select mid,
  118. month(date(substr(CAST (old_pg_txn_started_at AS varchar), 1, 10))) Month ,
  119. count(transaction_id) cbCount,
  120. sum(cbGMV) cbGMV
  121. from (
  122. select
  123. transaction_id,
  124. max(old_pg_mid) mid,
  125. sum(chargeback_amount) cbGMV,
  126. max(old_pg_txn_started_at) old_pg_txn_started_at
  127. from
  128. cdp_risk_transform.transaction_level_chargeback_snapshot_v3
  129. WHERE old_pg_ingest_date >= date'2024-10-01'
  130. AND date(substr(CAST (old_pg_txn_started_at AS varchar), 1, 10))
  131. between date'2024-10-01' and date '2025-02-28'
  132. group by 1)
  133. group by 1,2) as cb on pg.mid=cb.mid and pg.Month=cb.Month
  134. where pg.mid = 'NEHAEL54380289516455'
  135. group by 1,2,3,4,5,6,7;
content_copyCOPY