Agent skill
natural-language-sql
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/natural-language-sql
SKILL.md
🗄️ Natural Language SQL Skill
name: natural-language-sql description: Convert natural language queries to SQL and explain SQL in plain language
🎯 Purpose
แปลง natural language เป็น SQL queries และอธิบาย SQL ด้วยภาษาธรรมดา
📋 When to Use
- Write SQL from descriptions
- Explain existing queries
- Learn SQL syntax
- Quick data exploration
- Non-technical stakeholders
🔧 Translation Examples
Simple Queries
"แสดงรายชื่อลูกค้าทั้งหมด"
↓
SELECT * FROM customers;
"หาลูกค้าที่ชื่อ John"
↓
SELECT * FROM customers WHERE name = 'John';
Aggregations
"นับจำนวนออเดอร์ทั้งหมด"
↓
SELECT COUNT(*) FROM orders;
"ยอดขายรวมต่อเดือน"
↓
SELECT
DATE_TRUNC('month', created_at) AS month,
SUM(total) AS revenue
FROM orders
GROUP BY DATE_TRUNC('month', created_at)
ORDER BY month;
Joins
"ออเดอร์พร้อมชื่อลูกค้า"
↓
SELECT o.*, c.name AS customer_name
FROM orders o
JOIN customers c ON o.customer_id = c.id;
Complex Queries
"Top 10 ลูกค้าที่ซื้อมากที่สุดในปี 2024"
↓
SELECT
c.name,
SUM(o.total) AS total_spent
FROM customers c
JOIN orders o ON c.id = o.customer_id
WHERE o.created_at >= '2024-01-01'
GROUP BY c.id, c.name
ORDER BY total_spent DESC
LIMIT 10;
📊 SQL Patterns
| Natural Language | SQL Pattern |
|---|---|
| ทั้งหมด | SELECT * |
| กรอง/ที่มี | WHERE |
| เรียงตาม | ORDER BY |
| จำนวน/รวม | COUNT/SUM |
| เฉลี่ย | AVG |
| กลุ่ม | GROUP BY |
| เชื่อม | JOIN |
| ไม่ซ้ำ | DISTINCT |
| จำกัด | LIMIT |
📝 Explain SQL
-- Input SQL
SELECT c.name, COUNT(o.id) AS order_count
FROM customers c
LEFT JOIN orders o ON c.id = o.customer_id
WHERE o.created_at >= '2024-01-01'
GROUP BY c.id, c.name
HAVING COUNT(o.id) > 5
ORDER BY order_count DESC;
Explanation:
- ดึงชื่อลูกค้าและนับจำนวนออเดอร์
- เชื่อมตาราง customers กับ orders (รวมลูกค้าที่ไม่มีออเดอร์)
- กรองเฉพาะออเดอร์ตั้งแต่ปี 2024
- จัดกลุ่มตามลูกค้า
- แสดงเฉพาะลูกค้าที่มีมากกว่า 5 ออเดอร์
- เรียงจากมากไปน้อย
✅ Best Practices
- Use parameterized queries
- Avoid SELECT *
- Index frequently filtered columns
- Limit results
- Test on small dataset first
🔗 Related Skills
database-management- DB operationsdata-analysis- Analyze resultsapi-design- SQL in APIs
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?