Database basic knowledge collation, common functions and common grammar

Source: Internet
Author: User

1 Common Database Aggregation functions
Max ()
Min ()
SUM ()
AVG ()
Count ()


2 string processing functions
Len () differs from datalength (): Len is the return character length datalength is the return byte length
LTrim () RTrim () Trim ()
IsNull (@FilterStr, N ") If space-time replaces it

CHARINDEX (N '; ', @TmpList) returns the starting position of an expression in a string instead of index
Paitndex ('%ssd% ', @temp) is basically similar to the CHARINDEX function

SUBSTRING (@TmpList, 1, @Index-1)

Replace (' string ', the character to replace ', ' replace the character ')
Uppre and Lower functions
Left (,) and right (,) take the number of characters before and after how many


3 Numeric functions
Ceiling () Take the whole big floor () take the whole take small
ABS () absolute value
Round (,) rounding
Square () squared
sqrt () Open radical
RAND () random value


4th-Period function
GETDATE () Get system time
DATEADD (time unit, plus minus variable, date) Date of addition and subtraction
DateDiff (Time unit, date, date) difference between two dates
DATEPART (time unit, date) remove the specified part of the date
Datename (time unit, date) Same as DatePart function
IsDate () determines whether to return 0 or 1 for the expected format

Time Unit format
YEAR,YY,YYYY (year)
QUARTER,MM,MM (month)
Dayofyear,dy, Y (Day of the week)
Day,dd,d (date)
WEEK,WK,WW (Day of the week)
Hour,hh (Hours)
Minute,mi,n (min)
Second,ss,s (SEC)
Millisecond,ms (MS)

5 Common Database syntax

Over () This function is an analytic function or a window function can be used in the background to do some operation examples:
Row_number () over (Partition by Group field order by sort field) to generate line numbers after grouping sorting

SUM () over (the Partition by Group field), for example, after grouping a column to add total

Sum,avg,count,min,max using Over (PARTITION by) statements


Returns the result filter substitution syntax
Case if RowNum > 1 then totalmeasuretime else 0 end
Case RowNum while >1 then totalmeasuretime Elee 0 End


Union merge two query results two query results must have the same column union All is all results including duplicates

Database basic knowledge collation, common functions and common grammar

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.