Comprehensive Quality Report
WITH quality_checks AS (
SELECT
'Null Check' AS check_type,
'email' AS column_name,
COUNT(*) FILTER (WHERE email IS NULL) AS failed_count,
COUNT(*) AS total_count
FROM users
UNION ALL
SELECT
'Format Check',
'email',
COUNT(*) FILTER (WHERE email !~ '^[^@]+@[^@]+\.[^@]+$'),
COUNT(*)
FROM users
UNION ALL
SELECT
'Uniqueness Check',
'email',
COUNT(*) - COUNT(DISTINCT email),
COUNT(*)
FROM users
UNION ALL
SELECT
'Range Check',
'age',
COUNT(*) FILTER (WHERE age < 0 OR age > 150),
COUNT(*)
FROM users
)
SELECT
check_type,
column_name,
failed_count,
total_count,
ROUND(100.0 * failed_count / NULLIF(total_count, 0), 2) AS failure_rate,
CASE
WHEN failed_count = 0 THEN 'PASS'
WHEN failed_count * 100.0 / total_count < 1 THEN 'WARNING'
ELSE 'FAIL'
END AS status
FROM quality_checks
ORDER BY failure_rate DESC;Data Completeness Score
SELECT
id,
(CASE WHEN column1 IS NOT NULL THEN 1 ELSE 0 END +
CASE WHEN column2 IS NOT NULL THEN 1 ELSE 0 END +
CASE WHEN column3 IS NOT NULL THEN 1 ELSE 0 END +
CASE WHEN column4 IS NOT NULL THEN 1 ELSE 0 END +
CASE WHEN column5 IS NOT NULL THEN 1 ELSE 0 END
) * 100.0 / 5 AS completeness_score
FROM table_name;Anomaly Detection
WITH stats AS (
SELECT
AVG(amount) AS mean,
STDDEV(amount) AS stddev
FROM transactions
)
SELECT t.*
FROM transactions t, stats s
WHERE ABS(t.amount - s.mean) > 3 * s.stddev;sql-analytics
Analytical and aggregation SQL — GROUP BY, ROLLUP, CUBE, GROUPING SETS, pivots, cohorts, funnels, retention, percentiles and statistical functions.
sql-debugger
Debug failing SQL or queries returning wrong results — interpret error messages, find causes of duplicates, missing rows, NULL surprises, fan-out joins and type mismatches, and produce a fixed query.
sql-dialect-translator
Translate SQL between dialects — PostgreSQL, MySQL, SQL Server (T-SQL), Oracle, SQLite — covering data types, functions, pagination, date handling, upserts and identity columns.
sql-optimizer
Rewrite slow SQL queries for performance — read execution plans (EXPLAIN / EXPLAIN ANALYZE), remove anti-patterns, make predicates sargable, choose JOIN/EXISTS strategies and suggest indexes.
sql-performance-tuning
Database-level SQL performance tuning — index design and maintenance, query profiling, statistics, partitioning, schema design, locking and configuration bottlenecks.
sql-query-explainer
Explain what an existing SQL query does in plain language — logical execution order, step-by-step breakdown of joins, filters, grouping and window logic, and the shape of the result.