Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. SELECT u.email, if(t1.email is null,0,1) is_t1, if(t2.email is null,0,1) is_t2,
  2. th.email_from_name as channel,
  3. lg.primary_location_id, lg.id as group_id,
  4. -- t1 - sent emails
  5. t1.facility_name as t1_facility_name,
  6. t1.fname as t1_fname, t1.lname as t1_lname,
  7. CONCAT_WS(', ', NULLIF(trim(t1.address),''), NULLIF(trim(t1.address2),'')) as t1_address,
  8. CONCAT_WS(', ', NULLIF(trim(t1.city),''), NULLIF(trim(t1.state),''), NULLIF(trim(t1.zip),'')) as t1_city_state_zip,
  9. CONCAT_WS(' ', cm.fname, cm.lname) as cm_name,
  10. -- t2 - sent letters
  11. t2.facility_name as t2_facility_name,
  12. t2.poc as t2_name,
  13. CONCAT_WS(', ', NULLIF(trim(t2.address),''), NULLIF(trim(t2.address2),'')) as t2_address,
  14. CONCAT_WS(', ', NULLIF(trim(t2.city),''), NULLIF(trim(t2.state),''), NULLIF(trim(t2.zip),'')) as t2_city_state_zip,
  15. t2.program_long_name as t2_program_long_name,
  16. t2.program_short_name as t2_program_short_name,
  17. t2.website as t2_website,
  18. t2.website2 as t2_website2,
  19. t2.support_email as t2_support_email,
  20. t2.support_phone as t2_support_phone,
  21. -- regular users - from email_campaign
  22. if (ec.email is not null,ec.body_html,null) as ec_html
  23. FROM user u
  24. LEFT JOIN (select distinct(lower(email)) as email,body_html from email_campaign WHERE campaign_data_id = 14 AND
  25. sent_date IS NOT NULL AND is_sent_successfully = 1 AND is_unsubscribed = 0) ec ON ec.email = u.email
  26. LEFT JOIN tmp_anndsc_letter1 t1 ON t1.email = u.email
  27. LEFT JOIN tmp_anndsc_letter2 t2 ON t2.email = u.email
  28. LEFT JOIN location loc ON loc.primary_contact_user_id = u.id
  29. LEFT JOIN location mloc ON mloc.id = u.location_id
  30. LEFT JOIN location_group lg ON lg.id = COALESCE(loc.location_group_id,mloc.location_group_id)
  31. LEFT JOIN user cm ON cm.id = lg.manager_id
  32. LEFT JOIN theme th ON th.id = COALESCE(NULLIF(u.theme_id,0),NULLIF(loc.theme_id,0),mloc.theme_id)
  33. WHERE LENGTH(u.email)>5 and (ec.email IS NOT NULL OR t1.email IS NOT NULL OR t2.email IS NOT NULL)
  34. AND u.id NOT IN (select user_id from file where internal_kind_id = 3)
  35. AND loc.id NOT IN (select location_id from file where internal_kind_id = 3)
  36. GROUP BY u.email LIMIT 0,10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement