sql入门教程:SQL ROUND() 实例教程
round ( )函数
round ( )函数是用来一轮数字领域的一些具体小数。
数据库round ( )语法
SELECT ROUND(column_name,decimals) FROM table_name
好下面我们来看看数据结构
| Parameter | Description |
|---|
| column_name | Required. The field to round. |
| decimals | Required. Specifies the number of decimals to be returned. |
实例教程.
| Id | ProductName | Unit | UnitPrice |
|---|
| 1 | Jarlsberg | 1000 g | 10.45 |
| 2 | Mascarpone | 1000 g | 32.56 |
| 3 | Gorgonzola | 1000 g | 15.67 |
现在,我们要显示产品名称和价格四舍五入至最接近的整数。
我们使用下面的SELECT语句:
SELECT ProductName, ROUND(UnitPrice,0) as UnitPrice FROM Persons
输出结果.
| ProductName | UnitPrice |
|---|
| Jarlsberg | 10 |
| Mascarpone | 33 |
| Gorgonzola | 16 |