1 、--Mathematical functions
Select degree, sqrt (degree) from score--open square, square root
Select Price, ceiling (value) from car--takes the smallest integer greater than the current decimal
Select price, floor from car--takes the largest integer smaller than the current decimal
Select Price, round (price,-1) from car--rounded up to keep several
Select ABS (-2)--Take absolute value
Select RAND () *100-generates a random number, by default it generates a number between 0-1
2 、--String Functions
Select LOWER (' Welcome ')--turn lowercase
Select UPPER (' Welcome ')--turn capital
Select LTRIM (' Hello ')--compress the left space
Select RTRIM (' Hello ')--compress the space on the right
SELECT * from News
Select Left (title,5) from News-intercepts a string from the side, cutting n characters
Select Right (title,5) from News-intercepts a string from the left, truncating n characters
Select substring (title,3,5) from news--intercepts a string from a location, intercept the length n
Select reverse (title) from News-Flip string
Select replace (title, ' China ', ' us ') from News--replace string
Select STUFF (title,4,3, ' China ') from news--to replace the string at the specified position
Select LEN (' Hello ')--the length of the string
3 、--Date Time function
SELECT * FROM Student
Select year (sbirthday) from student--take the years from the date time
Select Month (sbirthday) from student--take the month in the date time
Select Day (sbirthday) from student--days of the date and time taken
Select GETDATE ()--time to get the current system
Select DATEPART (yy,sbirthday) from student--part of date time
--Type conversion
Select Len (CAST (0.2 as varchar))--cast (source data as target type)
Basic Database Learning 5-Mathematical functions