- Home
- Skills
- Data & Databases
- SQL Analysis Assistant
Works with the AI Agents you already use
SQL Analysis Assistant
by Syed Najaf
Write, explain, debug, and improve analytical SQL queries for database analysis and real-world business problems.
Free
SQL Analysis Assistant
Example session with this skill installed
I need a PostgreSQL query to find the top 5 customers by total spend in 2023. I have 'orders' (id, customer_id, total_price, created_at) and 'users' (id, name, email).
- Read your context and instructions
- Compiled the sql analysis assistant
I will calculate the total spend per customer for the year 2023 by joining the users and orders tables, then filtering by date.
Top 5 Customers by Spend (PostgreSQL)
WITH customer_spending AS (
SELECT
u.id AS customer_id,
u.name AS customer_name,
SUM(o.total_price) AS total_spend,
COUNT(o.id) AS order_count
FROM users u
INNER JOIN orders o ON u.id = o.customer_id
WHERE o.created_at >= '2023-01-01'
AND o.created_at < '2024-01-01'
GROUP BY u.id, u.name
)
SELECT
customer_id,
customer_name,
total_spend,
order_count
FROM customer_spending
ORDER BY total_spend DESC
LIMIT 5;
Explanation:
- CTE (customer_spending): Isolates the aggregation logic to keep the final SELECT clean.
- Inner Join: Ensures we only include users who actually placed orders.
- Date Filtering: Uses a range (
>=and<) which is generally more index-friendly than functional extraction likeYEAR(). - Grouping: Groups by both ID and Name to satisfy standard SQL requirements while ensuring uniqueness via the ID.
Validation:
- Check if
total_spendfor a known high-value user matches their individual order history. - Run a count of rows in
ordersfor 2023 to ensure the sum oforder_countin this query (without the LIMIT) matches.
Assumptions:
total_pricedoes not include currency symbols and is a numeric type.created_atis a timestamp or date type compatible with standard ISO strings.
Next steps
- Verify if you need to exclude canceled or returned orders.
- Determine if guest checkouts (orders with null
customer_id) should be aggregated.
Connects securely to your tools. The creator never sees your data.
About this skill
SQL Analysis Assistant helps users solve analytical problems using clear and readable SQL.
It can:
- Write SQL queries from business questions.
- Explain existing SQL queries step by step.
- Debug syntax and logical errors.
- Improve query readability and performance.
- Explain joins, aggregations, subqueries, and CTEs.
- Help with window functions and ranking.
- Identify potential duplicate and join multiplication issues.
Supports common SQL dialects such as MySQL, PostgreSQL, SQL Server, and SQLite.
Designed for students, analysts, and professionals working with relational databases.
Requires manual input of table schemas and column names. Does not perform low-level hardware-specific performance tuning.
How to use
- 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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
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
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 12 days ago
- Free with an Agensi account
Requires
Nothing to install.
Permissions
What's inside
Frequently Asked Questions
New in Data & Databases
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Data & Databases.