现有一sql语句:select *
  from test_table a
 where a.test_col = string1
    or a.test_col = string2 
    or a.test_col = string3经过测试发现,返回的结果在test_col列上的顺序,并不一定是按照string1、string2、string3顺序来的,没有什么规律。现在需要返回结果必须按照string1、string2、string3的顺序来,有什么办法吗?

解决方案 »

  1.   


    select *
    from test_table a
    where a.test_col = string1
    or a.test_col = string2  
    or a.test_col = string3
    order by a.test_col
      

  2.   


    你的方法不对。因为我这里string1、string2  、string3并不一定是升序排列的,你直接按a.test_col升序排列了。
      

  3.   

    select *
      from test_table a
     where a.test_col = string1
      or a.test_col = string2  
      or a.test_col = string3
    order by decode(test_col,'string1',1,'string2',2,'string3',2)
      

  4.   

    高,实在是高!我咋就没想到用decode呢,呵呵!