如何在postgres中四舍五入
How to round up in postgres
我有一个学校列表,其中包含 8 年级的学生人数,我需要添加一个额外的字段,我可以在其中添加学生总数的 10% 并向上取整。但是它不是向上舍入而是向下舍入。
例如51名学生
51/10 = 5.1
这个值需要四舍五入到 6 而不是 5
我到底错过了什么?我什至四舍五入是因为 count 的值是整数吗?
select *, (studentcount + (studentcount/10)) as roundup
from (
select sch.SchoolID as sid, sch.Schoolname as sn, count(distinct s.studentid) as studentcount
from student s
join studentschool ss on ss.studentid=s.studentid
join school sch on sch.id = ss.schoolid
你应该试试 ceil
(function math doc)
ceil
: nearest integer greater than or equal to argument
select *, ceil(studentcount + (studentcount/10)) as roundup
from ...
我有一个学校列表,其中包含 8 年级的学生人数,我需要添加一个额外的字段,我可以在其中添加学生总数的 10% 并向上取整。但是它不是向上舍入而是向下舍入。
例如51名学生 51/10 = 5.1 这个值需要四舍五入到 6 而不是 5
我到底错过了什么?我什至四舍五入是因为 count 的值是整数吗?
select *, (studentcount + (studentcount/10)) as roundup
from (
select sch.SchoolID as sid, sch.Schoolname as sn, count(distinct s.studentid) as studentcount
from student s
join studentschool ss on ss.studentid=s.studentid
join school sch on sch.id = ss.schoolid
你应该试试 ceil
(function math doc)
ceil
: nearest integer greater than or equal to argument
select *, ceil(studentcount + (studentcount/10)) as roundup
from ...