(query, table_info, sql)
| 41 | |
| 42 | |
| 43 | def correct_sql_by_case(query, table_info, sql): |
| 44 | sql_prompt = "Please determine the type of question. If it is an extremum problem, modify the SQL accordingly. " \ |
| 45 | "If not, use the original SQL as the modified SQL." \ |
| 46 | "Q1: What is the name of the instructor who advises the student with the greatest number " \ |
| 47 | "of total credits?\n" \ |
| 48 | "original SQL: SELECT T2.name FROM instructor T2 JOIN advisor T1 ON T2.id = T1.i_id JOIN " \ |
| 49 | "student s ON T1.s_id = T3.id WHERE T3.tot_cred = (SELECT MAX(tot_cred) FROM student)\n" \ |
| 50 | "A: The question is an extremum problem, so i should modify the SQL. " \ |
| 51 | "The modified SQL: SELECT T2.name FROM advisor AS T1 JOIN instructor AS T2 ON T1.i_id = T2.id JOIN " \ |
| 52 | "student AS T3 ON T1.s_id = T3.id ORDER BY T3.tot_cred DESC LIMIT 1\n\n" \ |
| 53 | "Q2: Return the id and full name of the customer who has the fewest accounts.\n" \ |
| 54 | "original SQL: SELECT c.customer_id, c.customer_first_name, c.customer_last_name FROM CUSTOMERS c JOIN ACCOUNTS " \ |
| 55 | "a ON c.customer_id = a.customer_id GROUP BY c.customer_id HAVING COUNT(a.account_id) = (SELECT " \ |
| 56 | "COUNT(account_id) FROM ACCOUNTS GROUP BY customer_id ORDER BY COUNT(account_id) ASC LIMIT 1)\n" \ |
| 57 | "A: The question is an extremum problem, so i should modify the SQL. " \ |
| 58 | "The modified SQL: SELECT T1.customer_id, T2.customer_first_name, T2.customer_last_name FROM " \ |
| 59 | "Customers_cards AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY " \ |
| 60 | "T1.customer_id ORDER BY count(*) ASC LIMIT 1\n\n" \ |
| 61 | "Q3: What is the average hours across all projects?\n" \ |
| 62 | "original SQL: SELECT avg(hours) FROM projects" \ |
| 63 | "A: The question is not an extremum problem, so i should use the original SQL as the modified SQL." \ |
| 64 | "The modified SQL: SELECT avg(hours) FROM projects\n\n" \ |
| 65 | "Q4: {query}\n" \ |
| 66 | "{table_info}\n\n" \ |
| 67 | "original SQL: {sql}" \ |
| 68 | "A: " |
| 69 | prompt_dict = { |
| 70 | "query": query, |
| 71 | "table_info": table_info, |
| 72 | "sql": sql |
| 73 | } |
| 74 | sql_prompt = get_prompt_content(sql_prompt, prompt_dict) |
| 75 | sql_result = ask_llm(sql_prompt) |
| 76 | return sql_result |
no test coverage detected