1.4 SQL functions

Source: Internet
Author: User

1. Call aggregate function

Sum: Returns and/or non-duplicated data for all values

Avg: average and ignores null values

Min: Minimum value

Max: Max value

Count: Count function

Distinct: To go without repeating records

2. Mathematical functions

ABS: Absolute Value

Power: exponentiation. Example: Power (2,2): 2 of the 2-time Square

Rand: Random floating-point number, randomly taking a float value between 0-1

Round: Rounding. For example: Round (19.235467,3), which retains three digits after the decimal point

sqrt: square root

Square: Square

3. String function:

Ascii:

Left (' Fdksjahioa ', 2): 2nd character up

Right (' Fdksjahioa ', 2): 2nd character up

Len (' 23382748 '): Returns the number of characters (including front and back spaces)

Replace (' A ', ' B ', ' C '): Change the B part of A to C

Reverse (' asdfgh '): string in reverse order, with the result: ' HGFDSA '

STR (A,B,C): Converts a numeric variable into a character variable. A is a number, B is the total length, and C is the number of digits after the decimal point. Returns if the specified length is exceeded * *

SUBSTRING (' A ', 3,5): Takes a specified number of characters. Starting from the third bit in string A, take the fifth bit.

4. Functions of time and date:

GETDATE: Return to present time

Day: Returns the part of the integer date

Month (date): Returns the part of the month

Year (date): Returns the part of an annual

DateDiff (Day, ' time1 ', "time2"): Time 1 and time 2 are poor according to day's span. Day can be replaced by other time spans

DATEADD (Day,n, "Time"): Add N day units to times

5. Conversion function: Convert one data type to another data type

Cost (A as B). A is the variable that you want to format, and B is the format to change to.

Convert (' target type ', ' target ', ' changed format '). This function is primarily intended for functions that change the time type

1.4 SQL functions

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.