agentscope-examples/agents/harness-examples/harness-quickstart/src/main/resources/workspace/skills/query-writing/SKILL.md
Writes and executes SQL queries ranging from simple single-table SELECTs to complex multi-table JOINs, aggregations, window functions, and subqueries. Use when the user asks to query the database, retrieve data, filter records, rank results, or generate reports.
npx skillsauth add guanxuc/agentscope-java query-writingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use query-writing when the user:
sql_get_schema to confirm column names.sql_execute_query.SELECT COUNT(*) AS canadian_customers
FROM Customer
WHERE Country = 'Canada';
Break the query into subtasks:
- [ ] Identify all required tables
- [ ] Inspect schemas to find join columns
- [ ] Draft the JOIN structure
- [ ] Add aggregations and grouping
- [ ] Validate and run
Call sql_get_schema for EACH table involved to find the exact foreign key column names.
SELECT
<grouping columns>,
<aggregates>
FROM <primary table>
[INNER | LEFT] JOIN <table2> ON <fk> = <pk>
[JOIN ...]
WHERE <filters>
GROUP BY <non-aggregate columns>
HAVING <post-aggregation filters> -- optional
ORDER BY <sort column> [DESC]
LIMIT 10; -- always limit unless all rows requested
Before executing, verify:
Call sql_execute_query, then show:
SELECT
Artist.Name AS artist,
SUM(InvoiceLine.UnitPrice * InvoiceLine.Quantity) AS total_revenue
FROM Artist
JOIN Album ON Album.ArtistId = Artist.ArtistId
JOIN Track ON Track.AlbumId = Album.AlbumId
JOIN InvoiceLine ON InvoiceLine.TrackId = Track.TrackId
GROUP BY Artist.ArtistId, Artist.Name
ORDER BY total_revenue DESC
LIMIT 10;
SELECT
strftime('%Y-%m', InvoiceDate) AS month,
ROUND(SUM(Total), 2) AS monthly_revenue
FROM Invoice
WHERE strftime('%Y', InvoiceDate) = '2013'
GROUP BY month
ORDER BY month;
SELECT
e.FirstName || ' ' || e.LastName AS employee,
COUNT(c.CustomerId) AS customer_count
FROM Employee e
LEFT JOIN Customer c ON c.SupportRepId = e.EmployeeId
GROUP BY e.EmployeeId
ORDER BY customer_count DESC;
| Symptom | Action | |----------------------|--------| | Empty result | Check WHERE condition values (case-sensitive strings). Verify column exists. | | Syntax error | Re-read schema. Check GROUP BY includes all non-aggregate SELECT columns. | | Wrong row count | Look for duplicate rows caused by missing JOIN conditions. | | Result seems too high | Check for fan-out from multiple JOINs; may need DISTINCT or subquery. |
LIMIT (default 10) unless the user explicitly asks for all rows.e, c, inv) for readability in multi-table queries.SELECT * — name the columns you need.ROUND(SUM(Total), 2).tools
Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.
data-ai
Lists tables, describes columns and data types, identifies foreign key relationships, and maps entity relationships in the database. Use when the user asks about database structure, table layout, column types, what tables exist, foreign keys, or how entities relate to each other.
documentation
Discover schema, write SELECT-only SQLite queries, execute, and explain results (aligned with harness-example).
documentation
Discover schema, write SELECT-only SQLite queries, execute, and explain results (aligned with harness-example).