假设数据如下:
ID   DIV   NUM
1     1     1
1     2     1
2     1     3
2     2     3
3     1     2
3     2     2  每个ID 下均有DIV 1,2
保持这样的格式,再以num排序怎样得到如下结果
1     1     1
1     2     1
3     1     2
3     2     2 
2     1     3
2     2     3
 

解决方案 »

  1.   


    select * 
    from t1
    order by num,div
      

  2.   


    with t1 as 
    (
         select 1 id,1 div,1 num from dual
         union all
         select 1 id,2 div,1 num from dual
         union all
         select 2 id,1 div,3 num from dual
         union all
         select 2 id,2 div,3 num from dual
         union all
         select 3 id,1 div,2 num from dual
         union all
         select 3 id,2 div,2 num from dual
    )select * 
    from t1
    order by num,div    id    div    num
    ---------------------------
    1 1 1 1
    2 1 2 1
    3 3 1 2
    4 3 2 2
    5 2 1 3
    6 2 2 3
      

  3.   

    --如果每一组内num的值都是相同的话,这个sql就可以了
    select * 
    from t1
    order by num,div
      

  4.   


    每一id中div1、div2对应的num不相同,在保证每一id对应两个div的顺序下,以div1的num进行排列,则如何呢?
      

  5.   


    num不一样的情况下,如何排序?
      

  6.   

    是这样的,每个ID对应DIV1/DIV2 这个结构保持不变,DIV1/DIV2对应的num值不同,我想只以其中DIV1的值进行排序,而忽略DIV2的num值(也就是DIV2的num不参与到排序),请教下