Skip to content
Skillpedia
Databases6.2k Β· #14391

sql-analysis

What it does

This skill turns a business question into a checked SQL query and a small result table. It is for analysts and managers who need numbers from a database without writing the query themselves.

When to use it

  • βœ“When you ask how many, what the trend is, or what the top items are in a database.
  • βœ“When you want to compare two groups or two time periods using the data.
  • βœ“When you need a result table along with the query that produced it.

Skill link

https://github.com/agentscope-ai/agentscope-java/blob/main/agentscope-examples/agents/agentscope-dataagent/src/main/resources/shared/agents/data-agent/skills/sql-analysis/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/agentscope-ai/agentscope-java/blob/main/agentscope-examples/agents/agentscope-dataagent/src/main/resources/shared/agents/data-agent/skills/sql-analysis/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œHow many new customers did we get each month last year, by region? Show me the query and the table.”

5 new skills a week. 1 minute to read.

How it works

The skill restates the question as a metric with a grouping, a time window and a filter. It drafts the SQL, runs it, checks that the row count and results make sense, and then reports the table with the query.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

SQL Analysis Skill

Repeatable SOP for turning a business question into a verifiable SQL answer.

Steps

  1. Restate the question as a metric. In one sentence, write: "<metric> by <grouping> over <time window>, filtered by <filter>". If any of those four (metric / grouping / window / filter) is missing or ambiguous, ask one clarifying question and stop. Do not guess.

  2. Locate the source. Decide where the data lives:

    • Look in knowledge/ first for any schema notes, data-dictionary entries, or prior query examples uploaded by the user.
    • If the right table is not obvious, delegate to the data-explorer sub-agent with the metric definition as the prompt β€” its job is to identify the canonical source.
  3. Draft the query. Write the SQL in a fenced sql block. Conventions:

    • Always include the time window in a WHERE clause β€” never query the full history "just in case".
    • Always SELECT an explicit column list β€” never SELECT * in an answer.
    • Use CTEs (WITH x AS (...)) over nested subqueries for anything beyond two levels of nesting.
    • Comment any non-obvious filter (-- excludes internal test accounts).
  4. Validate before reporting. Run the query and check:

    • Row count is in the ballpark you expected (1 row, 10 rows, ~30 daily buckets, etc.). A surprising row count is almost always a bug β€” investigate.
    • No NULLs in the grouping column unless that is the intended cohort.
    • At least one numeric sanity check: a known total, a known reference value, or a min/max range that matches reality.
    • If anything looks off, do not report the number β€” fix the query first.
  5. Write the report. Use this exact structure:

    ## Answer
    <one-sentence direct answer with the headline number(s)>
    
    ## Result
    <small markdown table β€” at most ~15 rows; for longer results, summarise
    and offer to render a chart or attach the full CSV>
    
    ## Query
    ```sql
    <the exact query you ran>
    

    Sources & validation

    • Table(s): schema.table_name (row count, freshness if known)
    • Validation: <which sanity checks you ran and the result>
    • Caveats: <known data quality issues, missing dates, etc.>
    
    

Anti-patterns

  • ❌ Reporting a number without the query that produced it.
  • ❌ Using LIMIT N to "make the output fit" without explaining what got cut.
  • ❌ Reading a single row and reporting it as a trend.
  • ❌ Inventing a table or column name. If unsure, delegate to data-explorer.

When to delegate

  • The user's question requires probing several candidate tables / sources before any query can be written β†’ spawn data-explorer.
  • The user wants a polished written deliverable summarising several analyses (e.g. "weekly health report") β†’ spawn report-writer after you have the underlying numbers ready.
FAQ

Does it guess missing details?

No, if the metric, grouping, time window or filter is unclear, the skill asks one clarifying question.

Will it show the query?

Yes, it presents the SQL along with the result table.

Does it check the answer?

Yes, it checks that the number of rows and values look reasonable before reporting.

Details

Original description by the author

Answer a quantitative business question by writing a SQL query against the data warehouse, validating it, and presenting the result. Use when the user asks "how many...", "what's the trend of...", "compare X vs Y over...", "what's our top N...", or anything that resolves to a query against tabular data. Produces a small result table plus the underlying query.

repo: agentscope-ai/agentscope-java

Popularity

GitHub stars
6.2k
Ranking position
#14391
License
Apache-2.0
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills