with cte as( select playbook_users.user_id,language,device FROM playbook_users JOIN playbook_events ON playbook_users. user_id=playbook_events.user_id ) select language,COUNT(DISTINCT user_id) as total_count, COUNT(DISTINCT CASE when device IN ('MacBook-Pro','iPhone 5s','iPad-air') THEN user_id ELSE NULL END) as apple_users FROM cte GROUP BY language;