SQL QuestSQL Interview Questions › Subqueries & CTEs

3-Sigma Anomaly: Transaction Amount Outliers

HardProQuerying BasicsSubqueries & CTEsAggregation & GroupingJoins

The fraud analyst's first move: flag transactions with amount more than 3 standard deviations above the mean. Compute mean and stddev across all transactions, then return the outliers — these are the high-value fraud candidates worth investigating first. Show txn_id, account_id, amount, txn_at, z_score (rounded to 2 decimals). Order by z_score descending.

SQLite has no STDDEV — compute it yourself: SQRT(AVG((amount - mean)^2)).

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

transactions

txn_idaccount_idamounttxn_atmerchant_idlatlngstatus
1149151.842026-03-04T12:39:39.078Z2440.342-74.4092completed
22110.722026-03-04T13:04:50.641Z752.936613.3229completed
335158.782026-03-04T13:27:15.528Z2552.739713.3134completed

Expected output: High-value transaction outliers

Hint

This is a Pro challenge — the hint, the step-by-step tutor and the reference solution open in the app.

Concepts

SELECT CTE Aggregation JOIN Statistics

Practise the topic: SQL practice questions · CTE practice · GROUP BY exercises · JOIN practice · Advanced SQL interview questions

Related questions

Cumulative Distinct Customers Over TimeHard · FreeRunning Total RevenueHard · FreeYear-over-Year GrowthHard · Free7-Day Rolling Revenue AverageHard · FreeMulti-CTE Revenue PipelineHard · FreeWealthy Survivor ProfileHard · Pro

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test