就是一个最基本的select语句,但是要针对一个列排序,排序方式又不是传统的顺序,请教一下怎样排select * from t order by col正常这句话是按照col中的数据来排序的,但是我的col中数据只有这五个[initiated, validated, pre-approved, approved, rejected]如何按照上面的顺序排序呢谢谢

解决方案 »

  1.   

    select * from t order by find_in_set(col,'initiated, validated, pre-approved, approved, rejected');
      

  2.   

    select * from t order by instr('initiated, validated, pre-approved, approved, rejected',col)
      

  3.   

    这种情况下,如果不考虑移植,在MYSQL你可以考虑用 ENUM类型 而不是 CHAR类型。
      

  4.   

     order by (case when col='initiated' then 1 when col='validated' then 2 when col='pre-approved' then 3 when col='approved' then 4  when col='rejected' then 5 end)
      

  5.   

    最常见的处理如楼上.case貌似是标准sql中的,比较通用
      

  6.   

    http://www.w3school.com.cn/sql/sql_functions.asp
    instr 这是MS Access 中的 Scalar 函数?  我是mysql
      

  7.   


    INSTR(str,substr) Returns the position of the first occurrence of substring substr in string str. This is the same as the two-argument form of LOCATE(), except that the order of the arguments is reversed. mysql> SELECT INSTR('foobarbar', 'bar');
            -> 4
    mysql> SELECT INSTR('xbar', 'foobar');
            -> 0
      

  8.   


    原来用了这种方法  多谢 只是mysql里的看来内建函数还真是挺强大