oracle中将不同单位的数字按照大小排序怎么写sql

如图:
在这里插入图片描述
思路是需要一列转换为统一单位的数据,然后根据大小排序

--1.创建测试表
create table tmp as
select '10年'  bond_period from dual union all
select '2年'  bond_period from dual union all
select '91日14'  bond_period from dual union all
select '3年15'  bond_period from dual union all
select '182日'  bond_period from dual union all
select '6月'  bond_period from dual union all
select '7年'  bond_period from dual union all
select '1年'  bond_period from dual union all
select '15年'  bond_period from dual union all
select '20年'  bond_period from dual union all
select '273日'  bond_period from dual union all
select '3月'  bond_period from dual union all
select '5年'  bond_period from dual union all
select '30年'  bond_period from dual union all
select '8年'  bond_period from dual union all
select '50年'  bond_period from dual;
--2.sql实现
select bond_period,
       decode(str,'年',num * 360 ,'月',num * 30,num) days
  from(select bond_period,
              regexp_substr(bond_period,'[0-9]+') num, 
              regexp_substr(bond_period,'[^0-9]+') str
         from tmp
       )
order by days

decode的解->decode
regexp_substr的解释->regexp_substr1,regexp_substr2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值