如何在 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