Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    SQL Query Architect Skill

    1

    Translate business questions into schema-aware, optimized SQL for Snowflake, BigQuery, PostgreSQL, and Redshift.

    $4.99

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    SQL Query Architect Skill

    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_at for 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 referenceSupplied schema evidenceStatus / concern
    ordersordersConfirmed
    usersusersConfirmed
    o.customer_idcustomer_idConfirmed
    o.amountamountConfirmed
    o.statusstatusConfirmed

    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_at aligns with your reporting standards.
    • Run a COUNT(*) on orders where customer_id IS 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

    1. Intake where you provide the business question, database dialect, and relevant schema or DDL.
    2. Mapping where the agent identifies table relationships, grain, and metric definitions.
    3. Generation of formatted SQL using CTEs and explicit aliases for maintainability.
    4. 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. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 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

    Permissions

    Read Files
    Listed22 days ago

    What's inside

    Frequently Asked Questions

    Simply provide your table DDL (Data Definition Language) or a schema summary during the intake phase. The agent uses this metadata to map relationships and ensure every column and join in the generated SQL actually exists in your database.

    While standard LLMs often use generic syntax, this skill is pre-configured with the specific syntax requirements and optimization quirks of dialects like Snowflake, BigQuery, and Redshift to prevent execution errors.

    The skill provides a complete SQL script using Common Table Expressions (CTEs) for readability, a schema validation report, and a performance checklist tailored to your chosen warehouse.

    No, for security and compliance, the agent does not require direct access to your data. It generates the code based on the schema definitions you provide, allowing you to review and execute the SQL in your own secure environment.

    It is highly effective for complex logic like MRR calculations or attribution modeling, as it includes a specific 'Ambiguity Resolution' step to flag potential grain conflicts or double-counting issues before writing the code.

    New in Data & Databases