SQL Basics · OR · NOT · parentheses
4. North American customers who stayed
Concept: OR · NOT · parenthesesshow
OR keeps a row when either condition is true, and NOT flips a condition: NOT status = 'x' keeps everything except 'x'. When you mix them, SQL does AND before OR (like × before + in math), so a OR b AND c means a OR (b AND c). Put parentheses around the OR part to say what you mean: (a OR b) AND c.
Example (different data):
SELECT title, genre FROM books WHERE (genre = 'sci-fi' OR genre = 'fantasy') AND NOT format = 'audiobook';
Your task
Customer success is inviting North American customers to a user meetup, but people who already churned shouldn't get the invite.
Return name and country of every customer in Canada or the USA who has NOT churned (active_status is not 'churned'), sorted by name.
Solution unlocks after 3 more tries
Starting Postgres in your browser…
query.sql
Output
Write a query and press Run Query (Ctrl/⌘ + Enter).