use hahn;

select 
    d.Domain as Domain,
    m.Email as Email,
    if (m.GLOBAL_NOTIFICATION, "Да", "Нет") as GlobalNotification
from `//home/webmaster/users/lester/marketing/WMC8882` as d
left join `//home/webmaster/prod/analytics/mailings/base` as m
    on d.Domain == m.Domain
where Email is not null
    and Visible
    and LanguageRU
    and not IsEuropeanUser
group by d.Domain, m.Email, m.GLOBAL_NOTIFICATION
order by Domain, Email
