当前位置: 代码迷 >> Oracle面试 >> order by 排序有关问题
  详细解决方案

order by 排序有关问题

热度:8483   发布时间:2013-02-26 00:00:00.0
order by 排序问题!
打个比方说,"select * from table order by point_id,date"
在上面语句中,先是根据point_id排序,再是根据date排序.
我想问的是,在point_id里面,我还要按照(SZLY%,SZHG%,ZSSL%)这样的顺序进行排序了,我该怎么做呢?

------解决方案--------------------------------------------------------
order by decode(substr(point_id,1,4),'SZLY','0','SZHG','1','ZSSL','2',substr(point_id,1,4))||substr(point_id,5), date

函数排序,把前四个字符取出来,指定下顺序,再把剩下的部分带上就行了
------解决方案--------------------------------------------------------
能否贴点数据?

------解决方案--------------------------------------------------------
have a try using the following sql

select * from table
where point_id like 'SZLY%'
order by point_id,date

union

select * from table
where point_id like 'SZHG%'
order by point_id,date


union

select * from table
where point_id like 'ZSSL%'
order by point_id,date

union

......
  相关解决方案