Untitled

mail@pastecode.io avatar
unknown
sql
2 months ago
1.1 kB
1
Indexable
Never
SELECT 
    pa.first_name, 
    pa.last_name, 
    pa.id, 
    pa.primary_email, 
    pa.primary_phone,
    rm.name as "RM Name",
    ud.referral_id, 
    ud.affiliate_id, 
    el.utm_medium, 
    el.utm_campaign, 
    el.utm_source, 
    u.is_email_verified, 
    pa.pan, 
    pa.aadhaar, 
    ba.penny_drop, 
    pa.date_of_birth, 
    pa.gender, 
    pa.address_city, 
    pa.state,
    CASE WHEN pa.pan IS NULL OR pa.pan = '' THEN 'false' ELSE 'true' END AS pan_verified,
    CASE WHEN pa.aadhaar IS NULL THEN 'false' ELSE 'true' END AS aadhaar_verified
    
FROM 
    user.profile pa
    
LEFT JOIN 
    analytics.user_details ud ON pa.id = ud.user_id 
LEFT JOIN 
    user.relationship_manager_user_mapping rmum ON rmum.user_id = pa.id 
LEFT JOIN 
    user.relationship_manager rm ON rmum.relationship_manager_id = rm.id 
LEFT JOIN 
    user.bank_account ba ON ba.user_id = pa.id
LEFT JOIN 
    identity.user u ON pa.user_id = u.id
LEFT JOIN 
    event.event_log el ON el.user_id = u.id 
    
WHERE 
    rmum.state IN ('ACTIVE');
Leave a Comment