Basic Database Learning 5-Mathematical functions

Source: Internet
Author: User
Tags mathematical functions square root

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

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.