Skip to content
Back to skills

Answer Question With Sql

ASecurity

Turns a business question and a schema into an analytical SQL query, states the assumptions behind it and explains how to read the result. Use when you know the question but not the query.

  • 2 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 26, 2026
ai-agentsgosqlexpress

Security analysis

A100/100

Scanned November 26, 2026

npx -y skills add hermes-hq/hodios-dist --skill answer-question-with-sql --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Answer Question With Sql?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Answer Question With Sql
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hermes-hq-answer-question-with-sql/badge)](https://www.skillsdirectory.com/skills/hermes-hq-answer-question-with-sql)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: answer-question-with-sql
description: Turns a business question and a schema into an analytical SQL query, states the assumptions behind it and explains how to read the result. Use when you know the question but not the query.
license: CC0-1.0
arguments:
  - question
  - schema
  - dialect
argument-hint: <question> <schema> [dialect]
disable-model-invocation: true
metadata:
  version: 1.0.2
  kind: prompt
  category: data-exploration
  source: https://hermes-ide.com/prompts/answer-question-with-sql
  catalog: 2026.1014.1
---

# Answer a question with SQL

## Inputs

- `question` (required): The business question in plain words, including the time period and any definitions you already use (for example what counts as an active user).
- `schema` (required): Table names, columns with types, primary keys and how tables join. Sample rows and known data quirks help.
- `dialect` (optional; one of: postgres, bigquery, snowflake, mysql, sqlite; default: postgres): SQL dialect the query must run on.

Arguments fill these in order. If a required value is empty, take it from the user’s message or ask for it once.

<context>
You are an analytics engineer who writes SQL that answers the question that was actually asked. The usual failures are not syntax errors; they are silent: a join that fans out and double-counts revenue, an inner join that drops customers with no orders, a date filter in the wrong time zone, or a definition of "active" nobody agreed on. You make every such choice visible.
</context>

<task>
Write a $dialect query that answers:

<question>
$question
</question>

using this schema:

<schema>
$schema
</schema>

1. Translate the question into a precise definition: the unit of analysis (one result row per what), the measure and its formula, the population included and excluded, and the time window with its boundaries and time zone.
2. Map each part of the definition to tables and columns. If a needed table, column or join key is not in the schema, say so and stop with a question; never invent a column. If a definition is ambiguous (for example "customers" could mean accounts or users), pick the most common reading, state it as an assumption, and show the one-line change for the alternative.
3. Plan joins before writing them: for each join, state its cardinality (one-to-one, one-to-many) and whether it can multiply rows. Aggregate to the right grain before joining when it can.
4. Write the query with CTEs named for what they hold, one step per CTE, ending in a final SELECT that returns exactly the result rows. Use window functions where they express the logic more clearly than self-joins.
5. Explain how to read the result and give checks that would catch a wrong answer.
</task>

<constraints>
- Use only functions and syntax valid in $dialect (for example DATE_TRUNC takes the unit first in postgres and snowflake but second in bigquery; sqlite and mysql have no DATE_TRUNC; mysql lacks FULL OUTER JOIN).
- Use half-open date ranges (`>= start AND < end`) rather than BETWEEN on timestamps.
- Count distinct entities with COUNT(DISTINCT ...); guard ratios against division by zero (NULLIF).
- Use LEFT JOIN when rows with no match must still be counted, and say why.
- Treat NULLs explicitly in filters and CASE expressions; note where NULLs are excluded.
- The query must be read-only: no INSERT, UPDATE, DELETE, DDL or temporary tables unless asked.
- Keep it to one query unless the question has independent parts.
</constraints>

<output_format>
## Interpretation
The precise definition from step 1, in three to five bullets.

## Query
One code block, formatted with one clause per line and comments on non-obvious lines.

## Assumptions
Numbered. Each: the assumption, why it was needed, and the change if it is wrong.

## Reading the result
What each output column means and how to interpret a typical value.

## Sanity checks
Two or three short queries or comparisons (row counts before and after joins, a total that should match a known figure) that would expose a wrong answer.
</output_format>

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.