我不是要转换值,我是想将行转换为两列
你我按正常顺序取出来为
   a    11
   a    12
   b    23
   b    67而我想用一条Sql语句使取出来的数据成这样
a  11  12
b  23  67

解决方案 »

  1.   

    每一个最多有多少列有限制吗?a  11  12 ...
    比如:条数<20条
      

  2.   

    select t.col1,sum(decode(t.id,2,col2,0)),sum(decode(t.id,1,col2,0))
    from  (select mod(rownum,2)+1 id,col1,col2 from tbname) t
    group by t.col1;
      

  3.   

    select col1,max(decode(rm,1,col2)) c1,max(decode(rm,2,col2)) c2 from 
    (select col1,col2,row_number() over(partition by col1 order by rownum) rm from table_name)
    where rm<=2
    group by col1以上只是只取前两行数据,至于取多行数据由用户自定义了
      

  4.   

    你还在线吗?我在公司,机器上没有装Oracle。我有一个想法啊,但没有办法试!你能配合一下吗?
    第一,你先从你表中选取ROWNUM,告诉我ROWNUM是从0开始的连续的数,还是从1开始的连续的数?
    SQL> select rownum from table_name;
    第二,如果是从1开始连续的值,请在where 的后面加上条件:
    SQL>select rownum from table_name
        where rownum=2*rownum-1 ;
        如果是从0开始的连续的值,请在where的后面加上条件:
    SQL>select rownum from table_name
        where  rownum=2*(rownum+1)-1
     
    tell me the result !!!
      

  5.   

    谢谢各位,我的是这样解决的:
    上面的表
    select ANo,BNo from (
    select rownum as Rn,Tb.Col2 as ANo,Ta.Col2 as BNo
    from Table  Tb left join Table Ta
    on Ta.Col1=Tb.Col1 where  Ta.id is not null and Tb.Col1 <> Ta.Col2 order by Ta.Col1
    ) where mod(Rn,2)=1
      

  6.   

    select col1,min(col2),max(col2) from A group by col1;
      

  7.   

    to  bobfang(匆匆过客) :
       你试过了吗?我好长时间没写SQL了。看来无论哪件事总有最好的方法!
      

  8.   

    我试过 bobfang(匆匆过客)的了,确实可行,多谢!