Creators to follow

N
nadia_ux44 followers
T
tomasz_forms44 followers
D
david_ops41 followers
AboutTermsPrivacyHelp

© 2026 teliprompt

NE
neil_stats
4 months ago•
Data & Analytics

Anomaly detection with rolling z-score windows in SQL

Claude Opus 4.6
code output
#sql
#anomaly-detection
#z-score
#monitoring
#statistics
Views
8.3K
Copies
1.6K
Likes
663
Comments
0
Copy rate
19.0%

Prompt

You are a data scientist. Write a SQL anomaly detection query in [sql_dialect] for the metric [metric_name] in table [metrics_table] (columns: ts, value).

Use a rolling z-score over a [window_size]-row lookback window.

Requirements:
1. Compute rolling mean and stddev (exclude the current row from the baseline)
2. Produce a z-score, a boolean is_anomaly flag using threshold [z_threshold]
3. Classify anomalies as 'spike' or 'dip'
4. Suppress flags when stddev is near zero to avoid false positives on flat segments
5. Return only the most recent 30 days, with anomalies at the top

Customise this prompt

Fill in 5 variables to personalise this prompt

Preview
You are a data scientist. Write a SQL anomaly detection query in [sql_dialect] for the metric [metric_name] in table [metrics_table] (columns: ts, value). Use a rolling z-score over a [window_size]-row lookback window. Requirements: 1. Compute rolling mean and stddev (exclude the current row from the baseline) 2. Produce a z-score, a boolean is_anomaly flag using threshold [z_threshold] 3. Classify anomalies as 'spike' or 'dip' 4. Suppress flags when stddev is near zero to avoid false positives on flat segments 5. Return only the most recent 30 days, with anomalies at the top

Example output

Related prompts

SQL style guide for analytics teams (adopt in a week, not a quarter)by @marco_bi
Data & Analytics
Messy CSV data cleaning pipeline with validation rulesby @sunita_etl
Data & Analytics
Data warehouse naming convention guide your team will actually followby @sunita_etl
Data & Analytics
Metric anomaly detection explainer with root cause frameworkby @neil_stats
Data & Analytics