6.ROUND(),TRUNC()函数

内置的函数在处理数据时允许更大的灵活性。

ROUND()和TRUNC()函数允许您四舍五入和截断数值。

注意ROUND 是四舍五入,例:6.57 => 7 , 6.49 => 6

TRUNC 是截断,留下整数部分 6.57 => 6

ROUND Query:

SELECT fname, age, ROUND(age/7) AS age_dog_years 
    FROM tutorial 
        WHERE fname = 'Dave'

根据简单除之后为6.571428571428571,四舍五入为7

结果:

{
  "results": [
    {
      "age": 46,
      "age_dog_years": 7,
      "fname": "Dave"
    }
  ]
}

TRUNC Query:

SELECT fname, age, TRUNC(age/7) AS age_dog_years 
    FROM tutorial 
        WHERE fname = 'Dave'

结果:

{
  "results": [
    {
      "age": 46,
      "age_dog_years": 6,
      "fname": "Dave"
    }
  ]
}

Last updated

Was this helpful?