database table Students
Id |
Name |
Sex |
Age |
Address |
101 |
Zhanghan |
Man |
14 |
Hangzhou |
102 |
Ouyangqing |
Man |
13 |
Hangzhou |
103 |
Wu Hao |
Man |
14 |
Beijing |
104 |
Money into |
Man |
15 |
Shanghai |
105 |
Liu Fangfang |
Woman |
12 |
Thailand |
1, average AVG Syntax: SELECT AVG (column name) from table name example: Select AVG (age) as age_avg from students as means to redefine the output column name and output the result as the text following the as:
2. Returns the number of rows for the specified condition returns the value of the specified column (null does not count) if the column name is not added, the number in the table is returned in * instead of the syntax: SELECT COUNT (column name) the From table name returns the number of duplicate data that is excluded from the specified column syntax: SELECT COUNT (Dist INCT column name) from table name
Example: SELECT COUNT (*) as Students_number from students results:
3, return the first, the last, the maximum, the minimum, the sum of the data and the first article: The Last Day () Max: Max () Minimum: Min () sum: sum () syntax: select FIRST/LAST/MAX/MIN/SU M (age) as age_avg from students execution Reference 1, 2 example
4. Grouping syntax: Select column name from table name where column name = value Group By column name where as a judgment statement optional example: select SUM (age), address from students group by ad Dress results:
SUM (age) |
Address |
27 |
Hangzhou |
14 |
Beijing |
15 |
Shanghai |
12 |
Thailand |
5. Returns the length of the value in the Text field syntax: Select Len (column name) from indicates
6. Returns the current date and time syntax: Select Now () from table name
7. Formatting syntax for fields displayed by the function: Select Format (column name, specify display format) from table name
8. Convert the value of the function field to uppercase syntax: SELECT UCase (column name) from table name
9. Convert the value of the function field to lowercase syntax: Select LCase (column name) from table name
functions used in SQL queries