SQL ROUND Function


  SQL > SQL Commands > ROUND Function

The ROUND function in SQL is used to round a number to a specified precision. The syntax is:

ROUND (expression, [decimal place])

where [decimal place] indicates the number of decimal points returned. A negative number means the rounding will occur to the digit to the left of the decimal point. For example, -1 means the number will be rounded to the nearest tens.

Let's go through an example to see how the ROUND function is used. Let's assume we have the following table:

Table Student_Rating
StudentIDinteger
First_Namechar(20)
Ratingfloat

and this table contains the following rows:

Table Student_Rating
StudentIDFirst_NameRating
1Jenny85.235
2Bob92.52
3Alice3.9
4James120.1

Example 1

SQL:

SELECT First_Name, ROUND(Rating, 1) Rating FROM Student_Rating

Result:

First_NameInt_Score
Jenny85.2
Bob92.5
Alice3.9
James120.1

Example 2

SQL:

SELECT First_Name, ROUND(Rating, -1) Rating FROM Student_Rating

Result:

First_NameInt_Score
Jenny90
Bob90
Alice0
James120

SQL CAST Function >>

Link to this page: If you find this page useful, we encourage you to link to this page. Simply copy and paste the code below to your website, blog, or profile.



More 1Keydata Tutorials



Copyright © 2012   All Rights Reserved.         Privacy Policy  



SQL SELECT
SQL DISTINCT
SQL WHERE
SQL AND OR
SQL IN
SQL BETWEEN
SQL Wildcard
SQL LIKE
SQL ORDER BY
SQL Functions
SQL Average
SQL COUNT
SQL MAX
SQL MIN
SQL SUM
SQL GROUP BY
SQL HAVING
SQL ALIAS
SQL AS
SQL JOIN
SQL INNER JOIN
SQL OUTER JOIN
SQL LEFT OUTER JOIN
SQL CROSS JOIN
SQL SELECT UNIQUE
SQL ROUND
SQL CAST
SQL CONVERT
SQL CONCATENATE
SQL SUBSTRING
SQL INSTR
SQL TRIM
SQL LENGTH
SQL REPLACE
SQL DATEADD
SQL DATEDIFF
SQL DATEPART
SQL GETDATE
SQL SYSDATE

SQL CREATE TABLE
SQL CONSTRAINT
SQL NOT NULL
SQL DEFAULT
SQL UNIQUE
SQL CHECK
SQL PRIMARY KEY
SQL FOREIGN KEY
SQL View
SQL CREATE VIEW
SQL Index
SQL CREATE INDEX
SQL ALTER TABLE
SQL DROP TABLE
SQL TRUNCATE TABLE
SQL USE
SQL CREATE DATABASE
SQL DROP DATABASE
SQL INSERT INTO
SQL UPDATE
SQL DELETE FROM

SQL Jobs

Site Map
Resources