postgresql – 圆号UP到10的倍数

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

这样做很好,但看起来很丑陋.有更简单的做法吗?

你可以找到SQLFiddle here

select ceil(a::numeric / 10) * 10
from (values (100),(111),(123)) s(a);
 ?column? 
----------
      100
      120
      130

相关文章

项目需要,有个数据需要导入,拿到手一开始以为是mysql,结果...
本文小编为大家详细介绍“怎么查看PostgreSQL数据库中所有表...
错误现象问题原因这是在远程连接时pg_hba.conf文件没有配置正...
因本地资源有限,在公共测试环境搭建了PGsql环境,从数据库本...
wamp 环境 这个提示就是说你的版本低于10了。 先打印ph...
psycopg2.OperationalError: SSL SYSCALL error: EOF detect...