oracle,将不同单位的数字按照大小排序怎么写sql啊,在线等

南风吹-故人归 2017-12-04 04:47:59

数据如图,怎样按照大小排序啊
...全文
706 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 6 楼 qq646748739 的回复:
没问题的话,此楼结贴!
有 3年2月这种貌似不得行哦, 感觉要搞个递归拆开 然后乘了再加
  • 打赏
  • 举报
回复
厉害厉害,长见识了,谢谢各位大佬。
zbdzjx 2017-12-05
  • 打赏
  • 举报
回复
借用5楼数据
with t1(bond_period) as
(
select '10年'  bond_period from dual union all
select '5月'  bond_period from dual union all
select '91日'  bond_period from dual union all
select '3年4月'  bond_period from dual union all
select '6年182日'  bond_period from dual union all
select '6月23日'  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日45'  bond_period from dual union all
select '3月12'  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年123'  bond_period from dual
)
, t2 as(
select bond_period, replace(replace(replace(bond_period,'年', '*365+'), '月', '*30+'), '日', '+') c1 from t1
)
select bond_period, c1, dbms_aw.eval_number(case when c1 like '%+' then substr(c1, 1, length(c1)-1) else c1 end) c2 from t2
  • 打赏
  • 举报
回复
非常感谢,十分感谢
碧水幽幽泉 2017-12-04
  • 打赏
  • 举报
回复
没问题的话,此楼结贴!
碧水幽幽泉 2017-12-04
  • 打赏
  • 举报
回复
由于最小单位是日,在这就统一单位为日,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
  • 打赏
  • 举报
回复
就是需要一列转换为统一单位的数据,然后根据大小排序,
  • 打赏
  • 举报
回复
就是按照天数大小排序
碧水幽幽泉 2017-12-04
  • 打赏
  • 举报
回复
没有在线啊?
碧水幽幽泉 2017-12-04
  • 打赏
  • 举报
回复
有年,又有日。
你想要排序后是什么效果?

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧