如何对列的数据进行排序
例如有表TABLE_TEST
id   count_1  count_2  count_3  count_4  count_5
1       5         6        1       2       4
2       4        7        1        5       9
...............................
如何才能得到数据
id   count_1  count_2  count_3  count_4  count_5
1       1         2       4       5         6     
2      1         4        5       7        9能不能不使用循环对每天单独提取出来进行处理
因为数据量可能会上千万...有好的意见或者建议请不吝留言..
不省感激

解决方案 »

  1.   

    SQL> select * from test;        ID         T1         T2         T3         T4         T5
    ---------- ---------- ---------- ---------- ---------- ----------
             1          5          6          1          2          4
             2          4          7          1          5          9SQL> 
    SQL> select id,r1,r2,
      2  greatest(decode(t1,r1,0,r2,0,r4,0,r5,0,t1),
      3  decode(t2,r1,0,r2,0,r4,0,r5,0,t2),
      4  decode(t3,r1,0,r2,0,r4,0,r5,0,t3),
      5  decode(t4,r1,0,r2,0,r4,0,r5,0,t4),
      6  decode(t5,r1,0,r2,0,r4,0,r5,0,t5)) r3
      7  ,r4,r5
      8  from (
      9  select id,r1,least(decode(t1,r1,999,r5,999,t1),decode(t2,r1,999,r5,999,t2),decode(t3,r1,999,r5,999,t3),decode(t4,r1,999,r5,999,t4),decode(t5,r1,999,r5,999,t5)) r2,
     10  greatest(decode(t1,r1,0,r5,0,t1),decode(t2,r1,0,r5,0,t2),decode(t3,r1,0,r5,0,t3),decode(t4,r1,0,r5,0,t4),decode(t5,r1,0,r5,0,t5)) r4,r5,t1,t2,t3,t4,t5
     11  from (
     12  select least(t1,t2,t3,t4,t5) r1,greatest(t1,t2,t3,t4,t5) r5,id,t1,t2,t3,t4,t5 from test
     13  ))
     14  /        ID         R1         R2         R3         R4         R5
    ---------- ---------- ---------- ---------- ---------- ----------
             1          1          2          4          5          6
             2          1          4          5          7          9呵呵,没办法写了个很苯的sql,千万别这样.权当练手.
      

  2.   

    多谢谢指教
    least()
    greatest()
    这两个函数我还没用过.学习一下,
    再等等看有没其他高人再指教一下