怎么将数据库某个表的特定字段的所有数据中的几个特定字段排在查询语句的最前面。
可能很绕,具体意思就是select code from base_table;
          code字段的数据大概就40GP,20DH,40PC,20PH,20GP,20HD,40CH,4OHQ等类似的数据
          要求20GP,40GP,4OHQ这3个特定数据排在查询语句最前面
                    继续解决~谢谢。
          

解决方案 »

  1.   

    select code from (select code,decode(code,'20GP',0,'40GP',1,'40HQ',2,9) orderflag from base_table) order by orderflag asc
      

  2.   


    SQL> with t as(
      2       select '40GP' code from dual union all
      3       select '20DH' from dual union all
      4       select '40PC' from dual union all
      5       select '20PH' from dual union all
      6       select '20GP' from dual union all
      7       select '20HD' from dual union all
      8       select '40CH' from dual union all
      9       select '40HQ' from dual)
     10  select * from t
     11  order by decode(code,'20GP',0,
     12                  '40GP',1,
     13                  '40HQ',2)
     14  /
     
    CODE
    ----
    20GP
    40GP
    40HQ
    20DH
    20HD
    40CH
    40PC
    20PH