functions used in SQL queries

Source: Internet
Author: User

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:
Age_avg
13.6

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:
Students_number
5

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.