oracle sql语句
表数据如下:
id   name   note
1    张三  备注一
2    李四    备注二
3    陈五    备注三
4    王六    备注四
……sql语句的结果是:id   name   note    id2   name2   note2
1    张三  备注一    2    李四    备注二
3    陈五    备注三    4    王六    备注四
……意思就是把所有记录分两列显示,请大家帮帮忙,谢谢!

解决方案 »

  1.   

    select a.id,a.name,a.note,b.id,b.name,b.note from table a,table b
    where b.id=a.id+1 and mod(to_number(a.id),2)=1
    order by a.id;
      

  2.   

    上面那个是按id为varchar2写的,如果id为number的话用下面的
    select a.id,a.name,a.note,b.id,b.name,b.note from table a,table b
    where b.id=a.id+1 and mod(a.id,2)=1
    order by a.id;
      

  3.   

    只要能转成number就用第一个,如果不能转成number,那要看你按什么规则,把两条数据放一行了
      

  4.   

    单数行的我没有试,不过我估计那两个sql都可以
      

  5.   

    SELECT a.id,a.name,a.num,b.id,b.name,b.num 
    FROM (SELECT * FROM(SELECT id,name,ROWNUM AS num FROM YY_TEST)) a,
    (SELECT * FROM(SELECT id,name,ROWNUM AS num FROM YY_TEST)) b
    WHERE b.num=a.num+1 AND MOD(TO_NUMBER(a.num),2)=1
    ORDER BY a.num;
    这样当行数为偶数时没问题,当奇数时会最后一行记录不显示
      

  6.   

    你试试这个
    select a.id,a.name,a.note,b.id,b.name,b.note from table a left join table b on b.id=a.id+1 
    where mod(to_number(a.id),2)=1
    order by a.id;