某字段的值或null或0或1 
现在我想按1,0,null来排, 
可是order by aa desc 还是asc 
都达不到效果,desc把null排在了前面(null,1,0), asc又是(0,1,null)排,哪位高人有好的排法?
不考虑把字段属性加default 0,
尝试用case,when,then也未能实现

解决方案 »

  1.   


    SQL> select * from t1;                                    IDX CNAME
    --------------------------------------- ------------------------------------------------------------
                                          1 test
                                          1 test
                                          0 test
                                            test
                                          0 test
                                          1 test6 rows selectedSQL> select idx,cname from t1 order by decode(idx,1,2,0,1,0) desc;                                    IDX CNAME
    --------------------------------------- ------------------------------------------------------------
                                          1 test
                                          1 test
                                          1 test
                                          0 test
                                          0 test
                                            test6 rows selected
      

  2.   

    SELECT * FROM t ORDER BY decode(a,NULL,-1,a) DESC;
      

  3.   

    order by aa desc nulls last 
      

  4.   

    oracle不熟啊,有这么方法可以用,多谢