FINDING LANDLORD USERID

PHOTO EMBED

Thu Sep 29 2022 10:17:24 GMT+0000 (Coordinated Universal Time)

Saved by @shubhangi_burle

-- FINDING LANDLORD USERID
     SELECT DISTINCT A.landlord
     , IF(B.phone_number IS NOT NULL, B.phone_number, NULL) AS landlord_phoneno
     , IF(C.reciver_vpa IS NOT NULL, C.reciver_vpa, NULL) AS landlord_vpa
     , IF(B.user_id IS NOT NULL, B.user_id, C.user_id) as landlord_user_id
     , A.sender, D.city as 
     FROM
        (select distinct eventdata_merchantcontext_contactid as landlord
        , eventdata_transactionid AS txn_id
        ,eventdata_sender as sender
        ,eventdata_senderphone
        ,eventdata_totaltransactionamount as amt
        ,eventdata_senderglobalcardid as CC    
         from foxtrot_stream.payment_backend_transact
         where 0 = 0
         and year = 2022 and month = 8 AND day = 2
         and eventtype = 'PAYMENT'
         and eventdata_status = 'COMPLETED'
         and eventdata_receiveruser = 'PHONEPERENTPAYMENT'
         and eventdata_sendertype = 'INTERNAL_USER'
         AND eventdata_workflowtype = 'CONSUMER_TO_MERCHANT'
         AND eventdata_receiversubtype = 'ONLINE_MERCHANT'
         AND eventdata_receivertypeinrequest = 'MERCHANT'
         AND eventdata_receivertype = 'MERCHANT'
         AND ((LENGTH(eventdata_merchantcontext_contactid) = 10) OR (eventdata_merchantcontext_contactid LIKE '%@ybl') OR (eventdata_merchantcontext_contactid LIKE '%@ibl') OR (eventdata_merchantcontext_contactid LIKE '%@axl')))A
     LEFT JOIN
         (SELECT DISTINCT user_ext_id AS user_id, phone_number
         FROM users.users
         WHERE blacklisted = 0)B
     ON A.landlord = B.phone_number 
     LEFT JOIN
         (SELECT DISTINCT receiveruser as user_id, reciver_vpa 
         FROM fraud.transaction_details_v3
         WHERE year(updated_date) = 2022 AND Month(updated_date) = 8 AND Day(updated_date) = 2
         AND errorcode = 'SUCCESS' and pay_transaction_status = 'COMPLETED'
         AND ((reciver_vpa LIKE '%@ybl') OR (reciver_vpa LIKE '%@ibl') OR (reciver_vpa LIKE '%@axl')))C
     ON A.landlord = C.reciver_vpa
     INNER JOIN
        (SELECT DISTINCT user_id, city FROM edw_shared.user_dimension WHERE city IS NOT NULL)D
    ON A.sender = D.user_id
content_copyCOPY