Data Analyst interview questions
100 real questions with model answers and explanations for Middle candidates.
See a Data Analyst resume example →Practice with flashcards
Spaced repetition · Hunter Pass
Questions
The three functions differ in how they assign positions when values tie.
- ROW_NUMBER gives every row a unique sequential number, even when values tie.
- RANK gives tied rows the same number and skips later positions.
- DENSE_RANK gives tied rows the same number without leaving gaps.
- Use ROW_NUMBER for one-row deduplication and choose rank semantics deliberately for top-N results.
Why interviewers ask this: The interviewer checks whether the candidate has actually hit tie-handling bugs in production queries rather than memorized textbook definitions.
I deduplicate by ranking each user's records from newest to oldest.
- Compute ROW_NUMBER over PARTITION BY user_id and ORDER BY updated_at DESC.
- Filter the result to rn = 1 to retain one complete row per user.
- Add a stable tiebreaker such as the primary key after updated_at.
- Avoid GROUP BY with MAX when you need columns from the same latest record.
Why interviewers ask this: A strong answer includes the tiebreaker detail, which separates people who have debugged flaky dedup logic from those who have only seen the pattern.
A reliable 7-day rolling average starts from a complete daily series.
- Aggregate revenue to exactly one row per calendar day.
- Apply AVG over ROWS BETWEEN 6 PRECEDING AND CURRENT ROW.
- Join to a date spine so days without orders still appear.
- Fill missing daily revenue with zero when no orders truly means zero revenue.
Why interviewers ask this: The date spine detail is the real test, because rolling metrics over gappy data are a classic source of silently wrong dashboards.
I choose among these forms based on readability, reuse, and materialization needs.
- Use CTEs to name transformation stages and keep normal analytical SQL readable.
- Use a subquery for a small inline lookup or one simple nested operation.
- Use a temp table when several downstream queries reuse an expensive intermediate result.
- Check engine behavior because some warehouses re-execute a referenced CTE instead of materializing it.
Why interviewers ask this: The interviewer wants to hear reasoning about materialization and reuse, not just a stylistic preference for CTEs.
A right-table filter in WHERE is the usual reason a LEFT JOIN loses unmatched rows.
- Unmatched right-side columns are NULL after the join.
- A condition such as WHERE orders.status = 'paid' rejects those NULL rows.
- The surviving result therefore behaves like an INNER JOIN.
- Move the right-side condition into ON when unmatched left rows must remain.
Why interviewers ask this: This is a litmus test for real debugging experience, since almost every analyst has shipped this bug at least once and a strong candidate names it instantly.
Exact distinct counts are expensive because the engine must track every unique value.
- The operation needs substantial memory, hashing, or sorting on large tables.
- Approximate functions or HyperLogLog sketches trade roughly 1 to 2 percent error for much less compute.
- Pre-aggregate recurring distinct metrics into summary tables when exact reporting is required.
- Choose the method from the accuracy requirement rather than defaulting to the most expensive option.
Why interviewers ask this: The interviewer looks for awareness of the cost model of analytical databases and the pre-aggregation habit, not just knowledge that a magic function exists.
Basic first and last order dates can be computed in one grouped query.
- GROUP BY user_id and calculate MIN(order_date) and MAX(order_date).
- Apply the database's date-difference function to those two values.
- Use FIRST_VALUE or LAST_VALUE when attributes from the boundary orders are also needed.
- Give LAST_VALUE an unbounded following frame so it does not return the current row by default.
Why interviewers ask this: Mentioning the LAST_VALUE frame gotcha signals hands-on window function experience beyond copy-pasted snippets.
LAG and LEAD expose neighboring rows without a self-join.
- LAG reads a previous row and LEAD reads a following row within the chosen window.
- LAG(revenue) over ordered months places prior-month revenue beside the current value.
- Month-over-month growth is then current minus previous, divided by previous.
- Applying LAG to event timestamps also supports action-gap, session, and churn analysis.
Why interviewers ask this: A good answer ties the function to a business calculation rather than reciting syntax.
I separate query regressions caused by data, plans, and warehouse conditions.
- Compare current row counts, new partitions, and recent backfills with the last healthy run.
- Inspect the execution plan for lost partition pruning, full scans, or changed join order.
- Check whether a join became many-to-many and created a large fanout.
- Verify queue contention and compute size before assuming the SQL itself regressed.
Why interviewers ask this: The interviewer evaluates a structured method that separates data changes, plan changes, and infrastructure changes instead of random query rewriting.
I treat SQL NULLs as unknown values rather than ordinary comparable values.
- Prefer NOT EXISTS because NOT IN can return no rows when its subquery contains NULL.
- Remember that column-based counts and most aggregates skip NULL while all-row counts do not.
- Use COALESCE only where the business meaning of a replacement value is explicit.
- Profile NULL rates and use IS DISTINCT FROM for NULL-safe comparisons where supported.
Why interviewers ask this: Strong candidates name NOT IN plus NULL specifically, since it is the most damaging and least visible of these bugs.
A window function is the normal choice for comparing each row with its group average.
- AVG(order_value) OVER (PARTITION BY customer_id) keeps the original row grain.
- The deviation can be calculated directly beside each order.
- A pre-aggregated self-join adds code and creates another opportunity for join-key errors.
- Use the join form only for limited window support or aggregates built from a different filtered row set.
Why interviewers ask this: This checks whether the candidate has internalized windows as the default tool for row-versus-group comparisons.
WHERE filters source rows, while HAVING filters groups after aggregation.
- Put non-aggregate conditions in WHERE so unwanted rows are removed early.
- Use HAVING for conditions such as SUM(amount) > 1000.
- A plain row condition in HAVING may work but wastes aggregation effort.
- Classify each condition by whether it depends on an aggregate result.
Why interviewers ask this: The interviewer looks for the performance intuition behind the rule, not just the textbook distinction.
Sessionization is a gap-detection problem followed by a cumulative count.
- Use LAG to obtain each user's preceding event timestamp.
- Flag a new session when the prior event is absent or the gap exceeds 30 minutes.
- Take a running SUM of the flag per user to assign session numbers.
- Add a deterministic event tiebreaker when timestamps can be identical.
Why interviewers ask this: Sessionization is a standard middle-level pattern, and describing the flag-plus-running-sum trick fluently shows genuine event-data experience.
Percentiles describe skewed distributions better than an average alone.
- Use PERCENTILE_CONT(0.5) for an exact continuous median where supported.
- Use an approximate quantile function for very large warehouse datasets when suitable.
- Heavy-tailed revenue and latency can pull the mean far from a typical observation.
- Report the median with a tail measure such as p90 to show both typical values and the distribution's tail.
Why interviewers ask this: The interviewer wants the statistical reasoning about skew, not just the function name.
I default to UNION ALL unless deduplication is an explicit requirement.
- UNION ALL appends inputs without checking the combined rows for duplicates.
- UNION adds a global sort or hash step that can be costly on wide datasets.
- Automatic deduplication can hide duplicate records that should be investigated.
- Use UNION only after defining which selected columns make two output rows duplicates.
Why interviewers ask this: Defaulting to UNION ALL with a stated reason signals someone who thinks about both cost and unintended data loss.
Conditional aggregation is the portable way to pivot known values in SQL.
- Group by the dimension that should remain as rows.
- Build each output column with SUM and a CASE condition for its month.
- A native PIVOT operator is shorter but usually still requires enumerated column values.
- Keep truly dynamic presentation columns in the BI layer rather than generating unstable SQL.
Why interviewers ask this: Pushing dynamic pivots to the presentation layer shows architectural judgment, which matters more than syntax at this level.
Recursive CTEs are useful when the number of traversal steps is not known beforehand.
- Use them to walk parent-child hierarchies such as org charts or category trees.
- They can also generate date or number sequences on engines without generator functions.
- Rolling up costs through a parent-child department table is a practical example with variable branch depth.
- Add a depth limit or cycle check to prevent malformed relationships from looping indefinitely.
Why interviewers ask this: Naming the cycle guard shows the candidate has run recursion on messy real data, not just clean examples.
Partitioning and clustering matter because query shape determines how much data is scanned.
- Filter directly on the partition column so the engine can skip irrelevant partitions.
- Avoid wrapping that column in transformations that may prevent partition pruning.
- Filters and joins on clustering columns can reduce scanning within each partition.
- Inspect the table definition before writing a costly warehouse query.
Why interviewers ask this: The interviewer checks cost-awareness, since analysts who ignore pruning burn real money on modern warehouses.
A p-value measures how surprising the observed result is under a no-effect assumption.
- Start by assuming the tested change has no real effect.
- Imagine repeating the experiment and observing sampling variation under that assumption.
- The p-value is the chance of a result at least as extreme as the one observed.
- It is not the probability that the change worked or that the null hypothesis is true.
Why interviewers ask this: The interviewer tests both correct understanding and the ability to translate it without the classic inversion error.
A confidence interval communicates the sampling uncertainty around an estimate.
- A 95 percent procedure captures the true value in about 95 percent of repeated samples.
- Report an estimated lift together with its lower and upper bounds.
- An interval from -1 to +7 supports different decisions than one from +2 to +4.
- Compare the plausible range with business-relevant gains and losses, not just zero.
Why interviewers ask this: Using the interval to frame a business decision, rather than reciting the definition, is what distinguishes a working analyst.
Locked questions
- 21
Describe Type I and Type II errors and give a business case where one is clearly worse than the other.
hypothesis-testingbudget - 22
Give an example where correlation misled a team, and how you would probe whether a relationship is causal.
causalcorrelation - 23
What determines the sample size needed for a test, and which lever do teams most often ignore?
sampling - 24
When would you use a t-test versus a non-parametric test like Mann-Whitney?
hypothesis-testing - 25
What is Simpson's paradox, and how do you guard against it in routine analysis?
paradoxes - 26
How do you identify and handle confounders in an observational analysis?
causal - 27
You checked 20 metrics after an experiment and one is significant at 0.05. What is the problem and what do you do?
experimentsmonitoring - 28
Explain the difference between standard deviation and standard error, and why the distinction matters in reporting.
dispersioninferencedistinct - 29
How do you decide whether to remove an outlier from an analysis?
outliers - 30
Why does the central limit theorem matter for A/B tests on skewed metrics like revenue per user?
distributionscltmonitoring - 31
Design an A/B test for a redesigned checkout page from scratch. What do you nail down before launch?
ab-testingdesign - 32
A PM asks how long their test needs to run. What inputs do you ask for and how do you answer?
- 33
Why is checking test results daily and stopping when significance appears a problem?
- 34
Your test ends with a +2 percent lift but p = 0.2. The PM asks if we should ship. What do you say?
- 35
How do you choose the randomization unit for an experiment, and what goes wrong with the wrong choice?
experiments - 36
What is an A/A test and when would you actually run one?
- 37
What is tricky about ratio metrics like click-through rate in A/B tests?
ab-testingmonitoringtesting - 38
How do novelty and primacy effects distort experiment results, and how do you account for them?
experiments - 39
What is sample ratio mismatch and why should it stop an analysis cold?
srm - 40
The overall test result is flat but one segment shows a strong win. How do you interpret that?
- 41
How does your dashboard design differ for an executive audience versus an operational team?
design - 42
Extract versus live connection in Tableau, or import versus DirectQuery in Power BI: how do you choose?
bi - 43
A stakeholder complains a dashboard takes a minute to load. How do you attack the problem?
stakeholder-managementcommunication - 44
How do you choose chart types, and when is a plain table the right answer?
chart-choice - 45
You discover a dashboard you maintain has had no viewers for two months. What do you do?
- 46
Why centralize metric definitions in a semantic layer instead of letting each dashboard compute its own?
semantic-layermonitoring - 47
How do you handle time zones in reporting, and where do the classic bugs hide?
soft-skills - 48
When do you replace a static report with automated alerting, and how do you avoid alert fatigue?
alerting - 49
Explain the star schema and why analysts should care about facts versus dimensions.
schemamodeling - 50
What are type 1 and type 2 slowly changing dimensions, and when does the difference bite an analyst?
scd - 51
What problems does dbt solve for an analytics team compared to a folder of scheduled SQL scripts?
sqldbt - 52
Incremental models versus full refresh: how do you decide, and what goes wrong with incremental logic?
- 53
What actually changed in the shift from ETL to ELT, and why does it matter for analysts?
etl - 54
What data tests would you put on a revenue table before letting dashboards depend on it?
testing - 55
What does the grain of a table mean, and why do you determine it before writing any query?
queries - 56
Why should a data pipeline be idempotent, and how do you make a daily load idempotent in practice?
pipelinesidempotencyci-cd - 57
Your daily report locks numbers at 6 am, but some events arrive hours or days late. How do you handle it?
soft-skills - 58
When do you prefer a denormalized wide table over a normalized model for analytics?
normalizationdenormalization - 59
Walk me through building a retention cohort analysis. What decisions shape the result?
retentioncohorts - 60
How do you define steps for a funnel analysis, and what do you do with users who skip steps?
funnel - 61
One product's retention curve flattens at 25 percent, another declines steadily to zero. What do you conclude?
retention - 62
How do you choose segmentation variables so the segments are actually actionable?
- 63
Explain RFM segmentation and when it is the right tool.
- 64
Newer signup cohorts retain visibly worse than older ones. How do you investigate?
cohorts - 65
How does the choice of conversion window change funnel numbers, and how do you pick one?
funnel - 66
Behavioral clustering like k-means versus rule-based segments: when do you use each?
clustering - 67
A stakeholder says sales are down, can you look into it. What do you do before writing any SQL?
stakeholder-managementsqlcommunication - 68
What makes a metric definition complete enough to implement without follow-up questions?
monitoring - 69
Explain the relationship between a north star metric and guardrail metrics.
north-starguardrailsmonitoring - 70
Two teams report different numbers of active users and both insist they are right. How do you resolve it?
- 71
A stakeholder asks you for data to support a decision they have clearly already made. How do you handle it?
soft-skillscommunicationstakeholder-management - 72
How do you prioritize when ad-hoc requests keep interrupting your longer-term analytical projects?
prioritization - 73
How do you structure a findings presentation for executives?
- 74
When do you tell a stakeholder that the data cannot answer their question, and what do you offer instead?
stakeholder-managementcommunication - 75
A pandas merge silently multiplied your row count. What happened and how do you prevent it?
pandas - 76
In pandas groupby, when do you use transform instead of agg?
pandas - 77
You receive a 30 GB CSV and your machine has 16 GB of RAM. What are your options?
- 78
What does SettingWithCopyWarning mean, and how do you write pandas code that avoids it?
pandas - 79
Why is df.apply with a row-wise lambda slow, and what do you do instead?
lambda - 80
How do you aggregate event-level data to weekly time series in pandas, and what silently goes wrong?
aggregationpandas - 81
When do you use pd.concat versus merge, and what is the most common concat mistake?
ownershippandas - 82
What is your decision process for handling missing values in an analysis dataset?
missing-dataconcurrency - 83
Your notebook analysis needs to be rerun by a colleague in six months. What do you do differently from a throwaway notebook?
- 84
The same metric computed in pandas and in SQL gives different results on the same source data. Where do you look?
sqlmonitoringpandas - 85
Your dashboard shows monthly revenue 8 percent below what finance reports. How do you reconcile systematically?
system-design - 86
Yesterday's revenue in the dashboard dropped 30 percent overnight. What are your first three checks?
- 87
How do you detect and handle duplicate events inflating product metrics?
monitoring - 88
A tracking change redefined a key event mid-quarter, breaking metric continuity. How do you preserve trust in the trend?
monitoring - 89
Google Analytics shows 20 percent more purchases than your backend database. Which number do you trust and why?
database - 90
What symptoms make you suspect a timezone bug in a report, and how do you confirm it?
- 91
What would you monitor proactively to catch data quality problems before stakeholders do?
qualitymonitoringcommunication - 92
How do you keep the team aware of known data caveats, like a two-week tracking outage last year?
- 93
You discover an error in an analysis you presented last month, and a decision was already made based on it. What do you do?
- 94
Tell me about a time your analysis changed a decision the team was about to make.
story - 95
What does your personal QA process look like before you share an analysis?
discoveryconcurrency - 96
How do you work with data engineers to get a pipeline change prioritized and shipped?
ci-cd - 97
A director asks for a number in an hour, but a rigorous answer needs three days. How do you handle it?
soft-skills - 98
How do you explain a technical limitation, like sampling in an analytics tool, to a non-technical stakeholder?
communicationsamplingstakeholder-management - 99
How do you keep your skills current, and what have you actually changed in your workflow in the last year?
- 100
An executive challenges your numbers in a live meeting, claiming their gut says otherwise. How do you respond?