Analysis of round (), floor (), Ceiling () function in SQL

Source: Internet
Author: User

A function module in the project used a scalar value function, and the function of the ceiling () function of the use of their own to find some information, the SQL of these functions to make a simple record, to facilitate their own learning. There are shortcomings welcome to make bricks Supplement

The 1.round () function follows the rounding principle, which is used to round a numeric field to a specified number of decimal digits

The 2.floor (value) function returns the smallest integer less than or equal to the specified value (value)

The 3.ceiling (value) function returns the smallest integer greater than or equal to the specified value (value)

For example: for 12.9,floor (12.9) return 12;ceiling (12.9) return 13;round (12.9,0) return 13

Where the standard usage of the round () function is:

Select round  from table_name

SQL instance: There is a Products table

Now, round the price to the nearest integer.

Select ProductName,round(UnitPrice,0 as from products

The results are as follows:

This is a self-made record, convenient for later study.

Analysis of round (), floor (), Ceiling () function in SQL

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.