加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – 圆号UP到10的倍数

发布时间:2020-12-13 16:31:47 所属栏目:百科 来源:网络整理
导读:如何在PostgreSQL中轻松地将数字UP转换为10的倍数? 例: In Out100 -- 100111 -- 120123 -- 130 样品数据: create table sample(mynumber numeric);insert into sample values (100);insert into sample values (111);insert into sample values (123); 我
如何在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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读