{"uid":"cap_MRDX2-kakR-yAxeLKJEqP","slug":"api-strale-io-08cbff2a","name":"SQL Query Explainer","description":"Explain a SQL query in plain language. Identifies tables, joins, filters, aggregations, and potential performance issues.","url":"https://api.strale.io/x402/sql-explain?utm_source=zero.xyz","method":"GET","headers":{},"bodySchema":{"type":"object","required":["sql"],"properties":{"sql":{"type":"string"}}},"responseSchema":{"tables":{"type":"array"},"operations":{"type":"array"},"plain_english":{"type":"string"},"potential_issues":{"type":"array"}},"example":{"request":{"sql":"SELECT u.id, u.name, COUNT(o.id) as order_count, SUM(o.amount) as total_spent FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.created_at > '2024-01-01' GROUP BY u.id, u.name HAVING COUNT(o.id) > 0 ORDER BY total_spent DESC LIMIT 10"},"response":{"_meta":{"payment":{"method":"x402","price_usd":0.054000000000000006,"settlement_id":"0x7f772b78b2bf5dabc952a4fbc36de09af7861748b5dcd5b31e398a18170f99b8"},"capability":"sql-explain","latency_ms":5646,"provenance":{"source":"claude-haiku","fetched_at":"2026-06-13T04:23:51.687Z"}},"steps":["Start with the users table and left join it with the orders table on user_id","Filter to only include users created after 2024-01-01","Group the results by user ID and name","Calculate the count of orders and sum of order amounts for each user","Filter groups to only include users with at least 1 order using HAVING clause","Sort results by total_spent in descending order","Return only the first 10 rows"],"dialect":"postgres","sql_length":243,"explanation":"This query retrieves the top 10 users created after January 1st, 2024 who have placed at least one order, showing their ID, name, total number of orders, and total amount spent, sorted by spending in descending order.","potential_issues":["LEFT JOIN followed by HAVING COUNT(o.id) > 0 negates the left join benefit - should use INNER JOIN instead","Missing indexes on orders.user_id and users.created_at could cause full table scans","Grouping by u.name in addition to u.id is redundant if id is the primary key"],"tables_referenced":["users","orders"],"optimization_suggestions":["Replace LEFT JOIN with INNER JOIN since the HAVING clause filters out users with no orders anyway","Create indexes on orders.user_id and users.created_at for faster filtering and joins","Remove u.name from GROUP BY clause if u.id is a primary key (PostgreSQL allows this, other databases may require it)","Consider materializing the user aggregations into a summary table if this query runs frequently"]}},"exampleRequest":{"sql":"SELECT u.id, u.name, COUNT(o.id) as order_count, SUM(o.amount) as total_spent FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.created_at > '2024-01-01' GROUP BY u.id, u.name HAVING COUNT(o.id) > 0 ORDER BY total_spent DESC LIMIT 10"},"tags":["x402"],"displayCostAmount":"0.054001","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"settled","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.054001/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.054","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.054","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_ajDFquAg1Yi-cjAioYCMU","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.054","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Explains a SQL query in plain English, identifying tables, joins, filters, aggregations, and potential performance issues","exampleAgentPrompt":"Can you explain what this SQL query does in plain English, including any joins, filters, aggregations, and whether there are any performance concerns? SELECT o.id, c.name, SUM(oi.quantity * oi.price) as total FROM orders o JOIN customers c ON o.customer_id = c.id JOIN order_items oi ON o.id = oi.order_id WHERE o.created_at > '2024-01-01' GROUP BY o.id, c.name HAVING total > 500","exampleUseCases":null,"resultDescription":"A plain-language breakdown of the SQL query, including identified tables, join relationships, filter conditions, aggregation logic, and flagged performance concerns such as missing indexes or expensive operations","failureModes":["Missing or empty 'sql' query parameter returns an error","Malformed or syntactically invalid SQL may produce incomplete or inaccurate analysis","Very long or deeply nested queries may not be fully analyzed","Payment failure (402) if USDC balance is insufficient"],"whenToPreferThis":"Use this endpoint when you need to explain or document a SQL query for non-technical stakeholders, review an unfamiliar query, or quickly audit a query for performance red flags — especially useful for data analysts, developers onboarding to a new codebase, or automated code review pipelines","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-10T12:35:22.200Z","isFirstParty":false,"canonicalSlug":"api-strale-io-08cbff2a"}