表里的数据a    b
1    100
3    150
1    200
5    300
2    400
2    300
4    600怎样才能排出这样的顺序,不用group bya    b
1    100
2    300
3    150
4    600
5    300
1    200
2    400谢谢各位了

解决方案 »

  1.   

    SQL> ed
    已写入 file afiedt.buf  1  with tb as(
      2  select 1 a,100 b from dual
      3  union all
      4  select 3,150 from dual
      5  union all
      6  select 1,200 from dual
      7  union all
      8  select 5,300 from dual
      9  union all
     10  select 2,400 from dual
     11  union all
     12  select 2,300 from dual
     13  union all
     14  select 4,600 from dual)
     15  select a,b
     16  from (select a,b,row_number() over(partition by a order by b) rn
     17         from tb)
     18* order by rn,a
    SQL> /         A          B
    ---------- ----------
             1        100
             2        300
             3        150
             4        600
             5        300
             1        200
             2        400已选择7行。
      

  2.   

    为什么要不用group by呢?需求为什么是这样的呢?
      

  3.   

    WITH tab as(
    SELECT 1 a,100 b FROM dual UNION ALL
    SELECT 3,150 FROM dual UNION ALL 
    SELECT 1,200 FROM dual UNION ALL 
    SELECT 5,300 FROM dual UNION ALL 
    SELECT 2,400 FROM dual UNION ALL 
    SELECT 2,300 FROM dual UNION ALL 
    SELECT 4,600 FROM dual 
    )
    select a,b from (
    select a,b,row_number() over(partition by a order by b) rn from tab)
    order by rn
    A  B
    -----------
    1 100
    2 300
    3 150
    4 600
    5 300
    1 200
    2 400