An equity analyst’s questions are mostly the same question asked of different tables: how fast is this growing, compared with what, and is the growth coming from new customers or old ones. When the data sits in a spreadsheet, the answer is a pivot table. When it sits in a database, as transaction panels, app usage and most internal company data do, the answer is SQL. Five constructs cover nearly all of it. This guide works each one on figures small enough to check by hand.
Why an analyst meets SQL at all
A company’s filed numbers arrive four times a year, and by the time they arrive the market has usually moved. The data that gives an earlier read is too large for a workbook: card transactions, web traffic, job postings, shipping records. It lives in a database, and the person who can query it directly does not wait for someone else to.
The same is true inside a company. An investor relations or corporate finance team answering "what was net revenue retention by cohort" is reading a customer table, not a ledger.
The five constructs, in the order they are needed
SQL is a small language. A query says which columns you want, from which table, for which rows, grouped how. Everything below is a variation on that sentence.
| Construct | What it does | The question it answers |
|---|---|---|
| SELECT ... WHERE | Picks columns and filters rows | What did this segment report in 2026 |
| GROUP BY | Collapses rows into totals | Revenue by segment, by quarter |
| JOIN | Matches rows across two tables | Revenue beside the consensus estimate for it |
| Window functions | Looks at other rows without collapsing them | Growth against the same quarter a year ago |
| Common table expressions | Names a step so the next step can use it | Any calculation with more than one stage |
A worked example: year-on-year growth with LAG
A table holds quarterly revenue for one segment, in millions. The task is growth against the same quarter of the prior year, which is the comparison that removes seasonality.
A window function reads another row while keeping the current one. LAG(revenue, 4) fetches the value four rows back when the rows are ordered by quarter, which for quarterly data is the same quarter a year earlier. Divide the current value by it and subtract one.
The first quarter of 2026 is 500 against 400 a year earlier: 500 / 400 - 1 = 25.0%. The second quarter is 546 against 420: 30.0%. Growth accelerated by five points, and sequential growth tells the same story, at 4.2% into the first quarter (500 against 480) and 9.2% into the second.
Two details decide whether the number is right. The window must be partitioned by segment, or the fourth row back belongs to a different business. And a quarter missing from the table shifts every later comparison by one, so count the rows per segment before trusting the output.
- SELECT quarter, revenue,
- revenue / LAG(revenue, 4) OVER (PARTITION BY segment ORDER BY quarter) - 1 AS yoy_growth
- FROM segment_revenue
| Quarter | Revenue | Same quarter, prior year | Year-on-year growth |
|---|---|---|---|
| Q1 2025 | 400 | ||
| Q2 2025 | 420 | ||
| Q3 2025 | 450 | ||
| Q4 2025 | 480 | ||
| Q1 2026 | 500 | 400 | 25.0% |
| Q2 2026 | 546 | 420 | 30.0% |
A second worked example: two kinds of retention
Group customers by the month they first paid, and follow each group forward. That is a cohort, and it answers a question a revenue total cannot: whether growth is new customers arriving or existing ones staying and spending more.
Take a cohort of 1,000 customers paying 50,000 a month between them. Twelve months later 800 are still paying, and those 800 pay 54,000 a month. Customer retention is 800 / 1,000 = 80%. Net revenue retention is 54,000 / 50,000 = 108%.
Both numbers are true and they describe different businesses. One in five customers left, and the ones who stayed more than made up the revenue. An analyst who reports only the 108% has hidden the churn, and one who reports only the 80% has hidden the expansion. The query for each is the same GROUP BY on cohort month, counting customers in one case and summing revenue in the other.
The join that triples your revenue
The most expensive mistake in analyst SQL produces no error. A revenue table has one row for each company and quarter. An estimates table has three rows for each company and quarter, one per broker. Join them on company and quarter and each revenue figure now appears three times.
Sum the revenue column and 500 becomes 1,500. The query ran, the output looks like a table, and the growth rates may even be right, because the tripling cancels in a ratio. The error shows only in a level.
The check takes one line: compare COUNT(*) on the joined result with the number of distinct company and quarter pairs (in most databases, a COUNT(*) over a SELECT DISTINCT of the two columns). If they differ, a table on one side has more than one row per key, and it needs to be collapsed with an average or a median before the join.
- Know the grain of every table: one row per what
- Collapse the many side before joining, not after
- Tie one total to a filed figure before using the rest
What a data-heavy research interview asks
Roles that list SQL usually test it with a small schema and a business question, and the question matters more than the syntax. "Which cohort retained best" is easy to query and easy to answer wrongly, because the newest cohort has had the least time to churn.
The strong answer names the trap before writing the query: compare cohorts at the same age, say what the denominator is, and state what the data cannot show. Syntax errors are forgiven. A confident number with the wrong denominator is not.
How to practise without a database of your own
A database engine that runs from a single file installs in a minute and reads CSV files directly, so any export you already have can be queried. Load segment revenue for three companies you follow from their filings and write the five queries above against it. Twenty lines of your own, checked against the filed totals, teach more than a course of exercises on someone else’s schema.
Next
See the method run on a real company
The research skills are written-up workflows for the tasks in this guide: an earnings review, a comps set, a filing comparison. Each one states its sources and shows its working.
Keep your SQL Cohort Drill results
SQL Cohort Drill is free without an account. A free account keeps your practice streak and the drills you have done on every device, and builds the next three things to do from your target. One email, no password.
Technology for finance: learn it, then use it
Python, SQL, version control and AI tools, used the way an analyst uses them: on data, with the checks.
Learn
Frequently asked questions
Do equity research analysts need SQL?
On a traditional sell-side team, rarely: the work is filings, models and writing. On data-driven teams and at funds that use transaction or usage data it is a daily tool, and postings for those seats say so. Read the posting rather than assuming either way.
What is a window function, in one sentence?
A calculation that reads other rows, such as the same quarter a year ago or a running total, while keeping every row in the output rather than collapsing them as GROUP BY does.
Is SQL harder to learn than Python?
It is smaller. Five constructs cover most analyst queries, and the language reads close to English. Most people can write useful queries within two weeks; the skill that takes longer is knowing the grain of each table and checking totals.
What is the difference between customer retention and net revenue retention?
Customer retention counts how many customers from a cohort are still paying. Net revenue retention measures what that cohort pays now against what it paid at the start, so it includes upgrades and price rises. A cohort can lose 20% of its customers and still show net revenue retention of 108%.

