SQL for Product Managers: Six Ideas, Five Real Queries and the Traps to Avoid
Six ideas cover most PM questions. Five real queries with real outputs, the traps that quietly produce wrong numbers, and a two-week plan.
A PM needs about six SQL ideas: SELECT/FROM, WHERE, GROUP BY, JOIN, CASE WHEN and date handling. Use LEFT JOIN so users without events stay in the denominator, put conditions in ON not WHERE, and count DISTINCT users rather than rows. Always sanity-check results, and write metric definitions down.
- Why a PM should learn SQL
- The sample data we will use
- The six ideas that cover most PM questions
- Query 1: How many signups per month?
- Query 2: Activation rate by channel
- Query 3: A funnel
- Query 4: Retention by signup month
- Query 5: Revenue per user by channel
- The traps that produce wrong numbers
- If your database is not SQLite
- How to get good in two weeks
- Common mistakes
You do not need to become an analyst. You need to answer, on your own and in five minutes, questions like “what share of last month’s signups completed a first lesson?” Without SQL, that is a request to a colleague, a two-day wait, and often an answer that does not quite match the question. With about six concepts, you can do it yourself. This guide teaches exactly those, using a sample database and queries that I have actually run, so the outputs you see are real.
Why a PM should learn SQL
- Speed: answer a question in minutes and keep your thinking going
- Precision: you define the metric exactly, instead of hoping an analyst guessed your meaning
- Credibility: engineers and analysts trust PMs who understand the data
- Catching errors: you notice when a number looks wrong before it reaches a slide
It also shows up in interviews. Some companies test SQL directly, and nearly all appreciate a PM who can reason about how data is structured. See the skills guide for where data fluency fits.
The sample data we will use
A small learning-app database with 600 users. Three tables:
| Table | Columns | One row means |
|---|---|---|
users | id, signup_date, channel, plan | One person who signed up |
events | user_id, event_name, event_date | One action a user took (signup, first_lesson, lesson_completed, purchase, session) |
orders | user_id, amount, order_date | One payment |
Every query below was run against this data. The dates are in ISO format (YYYY-MM-DD). I used SQLite, so a few date functions differ from other databases; there is a translation table near the end.
The six ideas that cover most PM questions
Query 1: How many signups per month?
Start with the simplest useful shape: group rows and count them.
SELECT strftime('%Y-%m', signup_date) AS month,
COUNT(*) AS signups
FROM users
GROUP BY month
ORDER BY month;
month | signups |
|---|---|
| 2026-01 | 219 |
| 2026-02 | 174 |
| 2026-03 | 207 |
GROUP BY collapses many rows into one per group, and COUNT(*) counts the rows in each. This is the pattern behind almost every dashboard number.
Query 2: Activation rate by channel
Now a real product question: what share of users did a first lesson within 7 days of signing up, split by acquisition channel? This needs a JOIN between users and events.
SELECT u.channel,
COUNT(DISTINCT u.id) AS signups,
COUNT(DISTINCT e.user_id) AS activated,
ROUND(100.0 * COUNT(DISTINCT e.user_id)
/ COUNT(DISTINCT u.id), 1) AS activation_pct
FROM users u
LEFT JOIN events e
ON e.user_id = u.id
AND e.event_name = 'first_lesson'
AND julianday(e.event_date) - julianday(u.signup_date) <= 7
GROUP BY u.channel
ORDER BY activation_pct DESC;
channel | signups | activated | activation_pct |
|---|---|---|---|
| referral | 120 | 84 | 70.0 |
| organic | 288 | 152 | 52.8 |
| ads | 192 | 75 | 39.1 |
Read the result: referral users activate at 70.0%, while ads users activate at 39.1%. That gap is exactly the kind of insight an average would hide. Notice two details. I used LEFT JOIN so users with no matching event still count in the denominator; an ordinary JOIN would silently drop them and make every rate look 100%. And the conditions on event_name and the date window are in the ON clause, not in WHERE. Moving them to WHERE would also throw away the users who did not activate, which is a very common mistake.
Query 3: A funnel
SELECT event_name,
COUNT(DISTINCT user_id) AS users
FROM events
WHERE event_name IN ('signup', 'first_lesson', 'lesson_completed', 'purchase')
GROUP BY event_name
ORDER BY users DESC;
event_name | users |
|---|---|
| signup | 600 |
| first_lesson | 384 |
| lesson_completed | 243 |
| purchase | 52 |
COUNT(DISTINCT user_id) counts each person once, however many times they did the action. That distinction matters enormously, as the next section shows. Reading down the list gives the shape of the funnel: many sign up, fewer start, fewer complete, fewer still pay.
Query 4: Retention by signup month
Here CASE WHEN flags whether a user had any activity at least 7 days after signing up, and we compute the share who did, by cohort.
SELECT strftime('%Y-%m', u.signup_date) AS cohort,
COUNT(DISTINCT u.id) AS users,
COUNT(DISTINCT CASE WHEN julianday(e.event_date) - julianday(u.signup_date) >= 7
THEN u.id END) AS retained,
ROUND(100.0 * COUNT(DISTINCT CASE WHEN julianday(e.event_date) - julianday(u.signup_date) >= 7
THEN u.id END)
/ COUNT(DISTINCT u.id), 1) AS retained_pct
FROM users u
LEFT JOIN events e ON e.user_id = u.id
GROUP BY cohort
ORDER BY cohort;
cohort | users | retained | retained_pct |
|---|---|---|---|
| 2026-01 | 219 | 112 | 51.1 |
| 2026-02 | 174 | 75 | 43.1 |
| 2026-03 | 207 | 102 | 49.3 |
This is a simple retention definition (“any activity 7 or more days later”). Many teams use stricter ones, such as “active exactly on day 7”. Whichever you use, write the definition down, because two people calculating “retention” differently will produce arguments instead of insight.
Query 5: Revenue per user by channel
SELECT u.channel,
COUNT(DISTINCT u.id) AS users,
COALESCE(SUM(o.amount), 0) AS revenue,
ROUND(COALESCE(SUM(o.amount), 0) * 1.0 / COUNT(DISTINCT u.id), 1) AS revenue_per_user
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
GROUP BY u.channel
ORDER BY revenue_per_user DESC;
channel | users | revenue | revenue_per_user |
|---|---|---|---|
| referral | 120 | 11486 | 95.7 |
| organic | 288 | 15974 | 55.5 |
| ads | 192 | 9488 | 49.4 |
COALESCE(SUM(...), 0) turns “no orders” (a missing value) into zero, so unpaid users do not break the maths. Revenue per user, split by channel, tells you which channels bring people who actually pay, which is usually a better guide to where to spend than signups alone.
The traps that produce wrong numbers
Trap 1: counting rows instead of people
Compare two versions of the same query. The first counts rows; the second counts distinct users.
SELECT u.channel, COUNT(*) AS activated
FROM users u
JOIN events e ON e.user_id = u.id
WHERE e.event_name IN ('first_lesson', 'lesson_completed')
GROUP BY u.channel;
channel | activated |
|---|---|
| ads | 159 |
| organic | 311 |
| referral | 157 |
SELECT u.channel, COUNT(DISTINCT u.id) AS activated
FROM users u
JOIN events e ON e.user_id = u.id
WHERE e.event_name IN ('first_lesson', 'lesson_completed')
GROUP BY u.channel;
channel | activated |
|---|---|
| ads | 95 |
| organic | 189 |
| referral | 100 |
The first version reports more “activated” users because someone who did both a first lesson and a completed lesson appears on two rows and is counted twice. The second is correct. Whenever you join to an events table, ask: could one person match several rows? If so, count distinct.
Trap 2: filtering in the wrong place on a LEFT JOIN
Put a condition on the right-hand table in WHERE and the LEFT JOIN quietly becomes an ordinary join, dropping the very rows you kept it for. Put the condition in ON instead, as in Query 2.
Trap 3: nulls and timezones
Comparisons with missing values return neither true nor false, so rows vanish from filters. Handle them explicitly with COALESCE or IS NULL. And dates recorded in different timezones can push events into the wrong day, which distorts daily and weekly metrics slightly. Agree one timezone for reporting.
If your database is not SQLite
The ideas are identical; only the date functions change. These are the translations for the two you will use most:
| Task | SQLite (used here) | PostgreSQL | MySQL |
|---|---|---|---|
| Month of a date | strftime('%Y-%m', d) | date_trunc('month', d) | DATE_FORMAT(d, '%Y-%m') |
| Days between two dates | julianday(a) - julianday(b) | a - b (for date types) | DATEDIFF(a, b) |
For BigQuery, use DATE_TRUNC and DATE_DIFF(a, b, DAY). When in doubt, search your database’s name with the task (“postgres days between dates”). Everyone does.
How to get good in two weeks
Install a free database tool, load a small dataset (or recreate the sample tables above), and run each query in this article. Then modify them: activation within 3 days instead of 7, revenue by month, funnel by channel. Finally, ask one real question about your own product and answer it yourself. That last step is where it sticks.
Common mistakes
Trusting a query because it ran without errors, when it may still answer a different question. Counting rows when you mean people. Forgetting to exclude test users. Comparing numbers defined differently. And never sanity-checking: if a rate is above 100% or below 1%, the query is wrong until proven otherwise. Also worth saying: reading data does not replace judgment. A correct number can still mislead, which is the theme of the metric we almost shipped the wrong feature for.
Next: product analytics for PMs for the bigger picture, and the metrics reference for what to calculate.
Frequently asked questions
Do product managers need to know SQL?
It is not always required, but it is very useful. Basic SQL lets a PM answer their own data questions in minutes, define metrics precisely, and catch data errors, and some companies test it in interviews.
Which SQL concepts should a PM learn first?
SELECT and FROM, WHERE, GROUP BY with aggregate functions, JOIN, CASE WHEN, and date handling. Together these cover most product questions such as funnels, activation, retention and revenue by segment.
What is the difference between COUNT(*) and COUNT(DISTINCT user_id)?
COUNT(*) counts rows, so a user with several matching events is counted several times. COUNT(DISTINCT user_id) counts each user once, which is usually what product metrics need.
Why use a LEFT JOIN when calculating rates?
A LEFT JOIN keeps users who have no matching event, so they remain in the denominator. An ordinary JOIN drops them and inflates the rate.
Want this sharpened for your specific situation?
I take on a small number of career calls and resume reviews each month.
See how we could work together