This invention discloses a Text-to-
SQL method and
system based on hierarchical multi-candidate
SQL scoring. In an online state, it receives query questions and performs table retrieval; it then performs mSchema synthesis, which includes table structure information, sample data of table fields, and
foreign key relationships between tables; it selects m reference examples, using one example at a time, and generates n
SQL statements using a
large model, resulting in a total of m*n SQL statements. The temperature parameter of the
large model is set to 1, and the sampling parameter is set to n. A first-level scoring method filters some SQL statements; a second-level scoring method filters others; a third-level scoring method obtains the cumulative
score for each SQL statement; the scores of each SQL statement are summed based on the scores obtained in the previous step to obtain the total
score for each SQL statement; finally, the SQL statement with the highest
score is selected as the final SQL statement, and the result is returned. This invention can lower the
data query threshold and improve the accuracy and
scenario adaptability of Text-to-SQL generation.