The 3 SQL queries every aspiring data analyst should know cold
Most data analytics courses start with theory. That's backwards.
Here are 3 queries I wish someone had drilled into me on day one:
1. The Revenue Cohort
SELECT DATE_TRUNC('month', signup_date) AS cohort,
COUNT(DISTINCT user_id) AS users,
SUM(revenue) AS total_revenue
FROM transactions
GROUP BY 1 ORDER BY 1;This tells you which signup cohorts are actually generating revenue. If you can't write this in your sleep, you're not ready for interviews.
2. The Retention Check
SELECT a.user_id,
a.first_purchase,
MIN(b.purchase_date) AS second_purchase
FROM (SELECT user_id, MIN(purchase_date) AS first_purchase FROM orders GROUP BY 1) a
LEFT JOIN orders b ON a.user_id = b.user_id AND b.purchase_date > a.first_purchase
GROUP BY 1, 2;Retention > acquisition. Every finance team cares about repeat behavior.
3. The Moving Average
SELECT date,
revenue,
AVG(revenue) OVER (ORDER BY date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS ma_7d
FROM daily_revenue;Smooths out noise. Essential for any financial reporting dashboard.
I'm building Sutra to teach this kind of practical, job-ready analytics. No fluff โ just the skills that get you hired.
Join free and start learning.
