SQL statement examples
This document provides examples of SQL statements for the data Q&A SQL template feature.
Starting January 2, 2025, you will no longer be able to configure SQL templates in Intelligent Chatbot (Tongyi Edition).
Access the SQL statement editor
In the Intelligent Chatbot space, choose table management > SQL template, and then click Create SQL Template.
-
If the chatbot fails to convert a natural language query into the correct SQL statement, you can write the statement manually. This improves the accuracy of the Q&A results.
-
This feature focuses on SQL queries.

SQL statement rules and examples
Rules
-
SQL is case-insensitive.
-
Use the
SELECTstatement to select data from a database. -
Use the
SELECT DISTINCTstatement to return only unique values. -
Use the
WHEREclause to filter records. -
Use the
ANDandORoperators to filter records based on more than one condition. -
Use the
ORDER BYkeyword to sort the result set. -
Use the
SELECT TOPclause to specify the number of records to return. -
Use the
LIKEoperator in aWHEREclause to search for a specified pattern in a column. -
Use the
BETWEENoperator to select values within a given range. The values can be numbers, text, or dates.
Examples
|
Capability |
Description |
Sample question |
Sample SQL |
|
Single- or multi-column query |
Select multiple columns by using |
List the names and prices of cars with fuel consumption greater than 8 and power less than 200. |
|
|
Aggregate function query |
Use aggregate functions such as |
What are the records for the Gold Award, and what is the latest award date? |
|
|
Value comparison |
Use comparison operators such as equal to, greater than, less than, and not equal to in the |
For positions requiring a bachelor's degree, what is the number of planned hires if the count of candidates who passed review is between 20 and 30? |
|
|
Multiple conditions |
Use |
What is the total reservoir capacity in the Yangtze River Basin and the Pearl River Basin? |
|
|
Auto-fill column names |
The system can infer the column name from the queried value, so you do not need to explicitly state it in your natural language question. |
Which students major in Computer Science or have excellent grades? What are their student IDs? |
|
|
Generalization |
Your natural language query does not need to use the exact column name from the table, as the system understands common variations. |
Which SUVs have a fuel consumption below 5? |
|
|
Top N |
Finds the top or bottom N items in a result set. |
What are the top 10 provinces by sales in 2023? |
|
|
Period-over-period (PoP) growth |
Measures the change in a value between two consecutive periods. |
What was the quarter-over-quarter (QoQ) sales growth for Sichuan province in Q3 of last year? |
|
|
Year-over-year (YoY) growth |
Measures the change in a value between the current period and the same period in the previous year. |
What is the year-over-year (YoY) sales growth for the dealer 'Mao Long' in the first quarter of this year? |
|