如何在Postgresql中轻松地将数字UP转换为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;
这样做很好,但看起来很丑陋.有更简单的做法吗?
select ceil(a::numeric / 10) * 10 from (values (100),(111),(123)) s(a); ?column? ---------- 100 120 130