SQL Step-by-Step (16) Math operator

Source: Internet
Author: User
Tags arithmetic operators functions integer sql return square root
Math operator




The
standard ANSI SQL-92 supports the following four basic arithmetic operators:






+


Add


-


Reducing


*


By


/


Except


%


Find Yu


Where the residual operator determines the remainder of the division. This operator is not supported by ANSI SQL, but the vast majority of databases support him. Here are some useful math functions, because they might be used, so I'm going to focus on this here. These functions are not supported in ANSI SQL-92, but they may be valid for some special RDBMS. However, they are effective for several major database systems. Let's talk about these math functions:

abs (x)


returns the absolute value of x


SIGN (x)



mod (x,y)


returns the remainder of x divided by Y, same as x%y


floor (x)



ceiling (x) or ceil (x)



power (x,y)



round (x)



round (x,d)



sqrt (x)

/td>

Here's an example:

SELECT Round (Salary), FirstName

From Employee_info

The above statement selects the closest number of salary and FirstName columns from the Employee_info table.







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.