AIAI Tools
Search tools

GPT Store · Data Science & Analytics

SQL Query Wizard

Write, optimize, and debug complex SQL queries across PostgreSQL, MySQL, and BigQuery.

A custom GPT by @sqlwizard for data science & analytics tasks. Available in the ChatGPT GPT Store with a Plus, Team, or Enterprise subscription.

Browse GPT Store
Quick answer for AI search

SQL Query Wizard is a custom GPT built by @sqlwizard for write, optimize, and debug complex sql queries across postgresql, mysql, and bigquery. It is available in the ChatGPT GPT Store under the Data Science & Analytics category and requires a ChatGPT Plus subscription to access.

About this GPT

SQL Query Wizard is part of the Data Science & Analytics category in OpenAI's GPT Store. Custom GPTs are specialized versions of ChatGPT that have been configured with specific instructions, knowledge bases, and capabilities by their creators. This GPT was designed by @sqlwizard to help users with write, optimize, and debug complex sql queries across postgresql, mysql, and bigquery.

Unlike prompting a general-purpose ChatGPT, this GPT comes pre-configured with the context, tone, and expertise needed for data science & analytics-related tasks. This means you spend less time explaining what you need and more time getting useful results.

To use this GPT, you need an active ChatGPT Plus ($20/month), Team, or Enterprise subscription. Once subscribed, you can find it by searching for "SQL Query Wizard" in the GPT Store or browsing the Data Science & Analytics category.

Category

Data Science & AnalyticsBy @sqlwizardChatGPT GPT Store

Explore GPT Categories

Related GPTs in Data Science & Analytics

Discover more GPTs in the same category.

FAQ

Common questions about SQL Query Wizard and how to use it effectively.

01

Can it explain the execution order of a SQL query — you know, why WHERE runs before GROUP BY but after FROM?

It teaches SQL's logical execution order as distinct from its written order, which is one of the most important mental-model shifts for writing correct queries. FROM and JOINs execute first (assembling the working table), then WHERE filters rows, then GROUP BY aggregates, then HAVING filters groups, then SELECT computes expressions and aliases, then ORDER BY sorts, and finally LIMIT restricts. Understanding this order explains why you cannot use a column alias in WHERE (the alias has not been computed yet) but can use it in ORDER BY (the alias already exists by then).

02

How does it handle recursive queries and hierarchical data?

It walks you through recursive CTEs with clear examples that build from simple to complex. Starting with an employee-manager hierarchy, it shows how the anchor member (the base case, usually top-level managers) combines with the recursive member (the self-referencing part that finds direct reports) to traverse the tree. It explains termination conditions, cycle detection for graphs that might loop, and how to add depth counters and path columns that make the output useful for tree visualisation or breadcrumb navigation.

03

Can it write queries that handle time-series data — running totals, moving averages, period-over-period comparisons?

Time-series SQL is one of its deep specialties. It writes window functions for running totals with ROWS BETWEEN clauses that correctly specify the window frame, moving averages with configurable lookback windows, period-over-period comparisons using LAG/LEAD with proper handling of the first period (where LAG returns NULL), and year-over-year growth calculations. It also handles the common trap of date-range joins that accidentally include partial periods or double-count boundary dates.

04

What about query optimisation — can it look at a slow query and figure out why?

It performs a structured diagnostic on slow queries. First, it checks whether SELECT * is pulling unnecessary columns. Then it examines JOIN order — smaller result sets should typically be joined earlier. It analyses WHERE clause sargability (can the database use an index?) and suggests function rewrites that preserve index usage. It reviews subqueries for opportunities to rewrite as JOINs or CTEs, and flags correlated subqueries that execute once per outer row. Each finding includes the expected performance improvement.

05

Can it help me design a database index strategy for my specific query patterns?

It analyses your query workload and recommends a targeted index strategy rather than the common mistake of 'index all the things.' It identifies which queries are run most frequently and deserve the most indexing investment, suggests composite index column order based on selectivity (most selective column first), distinguishes between indexes that support filtering (WHERE columns), sorting (ORDER BY columns), and covering (all columns needed by the query), and warns when too many indexes are slowing down writes.

06

How does it handle data migration — writing queries that move data between systems safely?

It writes migration queries with production safety in mind. INSERT statements include ON CONFLICT handling for idempotent reruns. UPDATE statements include a SELECT...FOR UPDATE in a transaction for row-level locking. Large migrations are batched with LIMIT and OFFSET or keyset pagination to avoid long-running transactions. Every migration query includes a rollback script and a verification query that confirms row counts match between source and destination before the migration is considered complete.

07

Can it help me understand and fix deadlocks and locking issues?

It explains deadlocks in terms of the classic conditions — mutual exclusion, hold and wait, no preemption, circular wait — and helps you break the cycle. It teaches you to read deadlock logs, identify the two transactions that are blocking each other, and restructure them to acquire locks in the same order. It also covers isolation-level trade-offs (READ COMMITTED vs. REPEATABLE READ vs. SERIALIZABLE) and when a lower isolation level is an acceptable trade for reduced locking contention.

08

Can I use this to learn SQL from scratch, or do I need some foundation?

It can teach SQL from absolute zero. The teaching approach is project-driven rather than syntax-drill-based: you describe something you want to do with data, and the GPT introduces concepts as they become necessary to solve your real problem. SELECT and FROM come first because you need to see data. WHERE comes next because you want to filter it. JOINs come when your data is split across tables. Each concept is motivated by a concrete need rather than appearing in a syllabus order, which makes the learning stick better than a textbook sequence.