我如何四舍五入到一个完整的整数 postgres

Tit*_*ito 2 sql postgresql rounding

我有像 10.43 这样的值,当我使用 round 函数时,它把它放在 10。我希望它实际上四舍五入到 11。有没有办法做到这一点?

例如,我的代码,我正在计算学生人数并将其除以参数。

 round((cast(COUNT(Distinct s.studentnr) as numeric)/cast(:Param as numeric)),2)

-- :Param is a user input e.g. 21 or 15
Run Code Online (Sandbox Code Playgroud)

所以最后如果我想要的是 52/21 = 3(不是 2)

或者我是否需要在这种情况下使用 case 语句?

Zay*_*hin 7

使用ceil功能

 --Returns 3
 select ceil( 52.00/21)
Run Code Online (Sandbox Code Playgroud)

http://sqlfiddle.com/#!17/9eecb/20356

  • @Jacob 60 和 61 都是“int”。将它们相除,得到 1(尝试“选择 61/60”)。然后 `ceil(1)` 变成 1,这是有道理的。尝试`select ceil (61/60::float)`,它变成2。 (4认同)