query-writing

Generate and execute SQL SELECT queries with schema inspection and validation.

Updated Apr 12, 2026
One-click install
npx skills add https://github.com/dotlab-hq/torque --skill query-writing-dotlab-hq
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: query-writing
Source: https://github.com/dotlab-hq/torque/tree/main/.agents/skills/query-writing
Command: npx skills add https://github.com/dotlab-hq/torque --skill query-writing-dotlab-hq

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill removes the uncertainty and manual effort of composing, validating, and executing SQL queries by guiding schema inspection, join planning, and safe execution so users can reliably retrieve and aggregate data without risking destructive operations.

Core Features & Use Cases

  • Schema-aware query construction: Inspect table schemas to choose relevant columns and join keys.
  • Simple and complex query workflows: Build single-table SELECTs, multi-table JOINs, aggregations, and subqueries with GROUP BY and ORDER BY.
  • Validation and error recovery: Verify JOIN conditions and GROUP BY correctness, handle empty results, syntax errors, and timeouts, and apply safe defaults such as LIMIT.
  • Use Case: Produce a revenue-by-country report by joining Invoice and Customer tables, aggregating totals, ordering by revenue, and limiting results.

Quick Start

Use the query-writing skill to generate and execute a SELECT query that returns the top 5 customers by total invoice amount joining the Invoice and Customer tables.

Frequently Asked Questions about query-writing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write SQL queries to join multiple tables and aggregate data?

Writing SQL queries for joining and aggregating data involves inspecting schemas to identify join keys, building multi-table JOINs, and using GROUP BY clauses for aggregation. This process ensures accurate data retrieval from relational databases.

What is the safest way to execute SQL queries for reporting tasks?

The safest way to execute SQL queries for reporting is by applying safe defaults such as LIMIT 5 and strictly avoiding destructive DML statements. This approach lets you retrieve and aggregate data while preventing accidental modifications to the database.

How do I validate SQL JOIN conditions and handle query errors?

To validate SQL JOIN conditions and handle errors, verify JOIN logic and GROUP BY correctness during construction, then implement error recovery for empty results, syntax issues, or timeouts to ensure robust query execution.

Can I generate a revenue-by-country report by joining Invoice and Customer tables?

Yes, you can generate a revenue-by-country report by joining Invoice and Customer tables. You aggregate total invoice amounts, group by country, order by revenue, and limit the results to produce the final reporting output.

Does this query generation approach support subqueries and complex filtering?

Yes, this query generation approach supports subqueries and complex filtering. It handles single-table SELECTs, multi-table JOINs, aggregations, and subqueries with GROUP BY and ORDER BY clauses for advanced data retrieval.