如何在PostgreSQL中轻松将数字向上舍入到10的倍数?
例子:
In Out
100 --> 100
111 --> 120
123 --> 130
样本数据:
create table sample(mynumber numeric);
insert into sample values (100);
insert into sample values (111);
insert into sample values (123);
我可以用:
select
mynumber,
case
when mynumber = round(mynumber,-1) then mynumber
else round(mynumber,-1) + 10 end as result
from
sample;
这很好用,但是看起来很丑。有更简单的方法吗?
您可以找到SQLFiddle here
最佳答案
select ceil(a::numeric / 10) * 10
from (values (100), (111), (123)) s(a);
?column?
----------
100
120
130
关于postgresql - 向上取整至10的倍数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16238522/