Convert natural language questions into SQL queries. Activates when users ask data questions in plain English like "show me users who signed up last week" or "find orders over $100".
Convert natural language questions into SQL queries using the database schema.
Activate when user asks questions like:
Before generating SQL, get tables and columns in one call:
whodb_tables(connection="...", include_columns=true) → Get all tables AND their column names, types, and keys
Parse the natural language request:
Build the query following SQL best practices:
SELECT columns
FROM table
[JOIN other_table ON condition]
WHERE filters
[GROUP BY columns]
[HAVING aggregate_condition]
ORDER BY column [ASC|DESC]
LIMIT n;
whodb_query(query="generated SQL")
| Natural Language | SQL Pattern |
|---|---|
| "last week/month/year" | WHERE date_col >= DATE_SUB(NOW(), INTERVAL 1 WEEK) |
| "more than X" / "greater than X" | WHERE col > X |
| "top N" | ORDER BY col DESC LIMIT N |
| "how many" | SELECT COUNT(*) |
| "total" / "sum of" | SELECT SUM(col) |
| "average" | SELECT AVG(col) |
| "for each" / "by" | GROUP BY col |
| "between X and Y" | WHERE col BETWEEN X AND Y |
| "contains" / "like" | WHERE col LIKE '%term%' |
| "starts with" | WHERE col LIKE 'term%' |
| "is empty" / "is null" | WHERE col IS NULL |
| "is not empty" | WHERE col IS NOT NULL |
WHERE created_at >= NOW() - INTERVAL '7 days'
WHERE created_at >= DATE_TRUNC('month', CURRENT_DATE)
WHERE created_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)
WHERE created_at >= DATE_FORMAT(NOW(), '%Y-%m-01')
WHERE created_at >= DATE('now', '-7 days')
WHERE created_at >= DATE('now', 'start of month')
SELECT * FROM users
WHERE created_at >= DATE_TRUNC('month', CURRENT_DATE)
ORDER BY created_at DESC;
SELECT p.name, SUM(oi.quantity) as total_sold
FROM products p
JOIN order_items oi ON p.id = oi.product_id
GROUP BY p.id, p.name
ORDER BY total_sold DESC
LIMIT 5;
SELECT customer_id, COUNT(*) as order_count
FROM orders
GROUP BY customer_id
ORDER BY order_count DESC;