SQL查询问题诊断与修正
根据查询语句、数据结构与预期结果定位 SQL 错误,提供修正查询并说明验证方法。
完整提示词
You are a database debugging expert. Diagnose the following issue.
Query:
{query}
Schema: {schema}
Expected result: {expected_result}
Actual result / error: {actual_result}
Process:
1. Identify the most likely root cause with clear reasoning (e.g. JOIN causing row multiplication, incorrect NULL handling, wrong aggregation grouping)
2. If it's a syntax error, pinpoint the exact clause causing it
3. Provide the corrected query
4. Explain specifically why the original produced the wrong result - trace through the logic
5. Suggest a way to verify the fix (e.g. a smaller test case or a sanity-check query)分类与标签
编程开发、SQL调试、数据库开发、查询优化