- Home
- Skills
- Data & Databases
- SQL Query Architect Skill
Works with the AI Agents you already use
SQL Query Architect Skill
Translate business questions into schema-aware, optimized SQL for Snowflake, BigQuery, PostgreSQL, and Redshift.
$4.99
SQL Query Architect Skill
Example session with this skill installed
Generate a Snowflake query to find the top 5 customers by total spend in 2023. Tables: 'orders' (id, customer_id, amount, status, created_at) and 'users' (id, email, region). Only count 'shipped'.
- Read your context and instructions
- Compiled the sql query architect
I have mapped your request to the provided Snowflake schema. The query focuses on aggregating 'shipped' orders at the user level for the 2023 calendar year.
SQL Query Architect Output
1. Understanding
- Business question: Top 5 customers by total spend in 2023.
- Output grain: One row per customer.
- Metric definitions: Total spend is the SUM of 'amount' for orders where status is 'shipped'.
- SQL dialect: Snowflake.
- Assumptions: Using
created_atfor the 2023 date boundary.
2. SQL Query
WITH customer_spend AS (
SELECT
u.email,
u.region,
SUM(o.amount) AS total_spend_2023
FROM orders AS o
INNER JOIN users AS u
ON o.customer_id = u.id
WHERE o.status = 'shipped'
AND o.created_at >= '2023-01-01'
AND o.created_at <= '2023-12-31'
GROUP BY 1, 2
)
SELECT
email,
region,
total_spend_2023
FROM customer_spend
ORDER BY total_spend_2023 DESC
LIMIT 5;
3. Schema Match
| SQL reference | Supplied schema evidence | Status / concern |
|---|---|---|
| orders | orders | Confirmed |
| users | users | Confirmed |
| o.customer_id | customer_id | Confirmed |
| o.amount | amount | Confirmed |
| o.status | status | Confirmed |
4. Explanation
The query uses a CTE to join orders and users on the customer ID. It filters for 'shipped' status and the 2023 date range before aggregating. The final SELECT retrieves the top 5 records by descending spend.
5. Correctness Checks
- Join Cardinality: INNER JOIN assumes every order has a valid user; check for orphaned customer IDs.
- Date Range: Used inclusive boundaries; verify if 2023-12-31 needs timestamp precision.
- Nulls: SUM(amount) will ignore NULL amounts; verify if NULL status should be handled.
6. Optimization Notes
Snowflake performs well with this structure. Ensure created_at is a clustering key if the orders table is massive.
Next steps
- Verify if 'shipped' is the only status representing successful payment.
- Confirm if the timezone for
created_ataligns with your reporting standards. - Run a
COUNT(*)onorderswherecustomer_idIS NULL to check join integrity.
Connects securely to your tools. The creator never sees your data.
About this skill
Writing manual SQL for complex business questions is prone to schema errors, incorrect join cardinality, and dialect mismatches. This skill acts as a schema-aware SQL engineer that translates natural language requirements into optimized, warehouse-specific queries. It eliminates the guesswork by mapping business logic directly to your DDL, ensuring every join, aggregation, and filter aligns with your actual data structure.
What it does
- Dialect translation generates SQL tailored for BigQuery, Snowflake, PostgreSQL, Redshift, Databricks, or SQL Server.
- Schema validation maps every table and column reference against your provided DDL to prevent syntax errors.
- Ambiguity resolution flags undefined metrics, grain conflicts, and missing business rules before writing code.
- Performance optimization suggests dialect-specific improvements like partition filtering and early aggregation.
- Correctness auditing provides a structured checklist for null handling, join cardinality, and date boundaries.
How it works
- Intake where you provide the business question, database dialect, and relevant schema or DDL.
- Mapping where the agent identifies table relationships, grain, and metric definitions.
- Generation of formatted SQL using CTEs and explicit aliases for maintainability.
- Verification via a schema match table and validation plan for safe execution.
Frameworks & tools
Supports major data warehouses including PostgreSQL, Snowflake, BigQuery, Amazon Redshift, Azure SQL, and Databricks SQL.
Why this beats prompting it yourself
Standard LLMs often hallucinate columns or use generic syntax that fails in specific warehouses. This skill enforces a strict schema-matching workflow and dialect-specific optimization that generic prompts ignore.
Use cases
- Generating complex monthly recurring revenue (MRR) reports from raw billing tables.
- Converting legacy SQL scripts from one warehouse dialect to another.
- Debugging join logic and double-counting issues in existing analytical queries.
Known limitations
Does not execute queries directly and requires provided schema/DDL for accuracy. Avoids generating credentials or connection strings.
Requires user-provided schema or DDL for accurate mapping. Cannot execute queries or verify data results without external tool access. Does not handle secrets or credentials.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 22 days ago