表中有两条数据,每条数据的前三个字段为公共字段数值都是一样的,后面字段数据都不一样。
其中有个序号字段,值分别是1和2,现在想要将序号为2的这条数据,去掉公共字段将其它的值合并到序号1的后面视作一条数据,用视图的方式查询。
求高人写个SQL语句。。谢谢!!!在线等。。

解决方案 »

  1.   


    --t你的表col1,col2,col3相同列,col4不同列
    select t1.col1,t1.col2,t1.col3,t1.col4,t2.col4
    from t t1,t t2
    where t1.序号=1 and t2.序号=2
      

  2.   


    -----假如你的表有6列,id,col1,col2,col3,col4,col5(col4,col5内容不相同)select a.col1 as acol1,a.col2 as acol2,a.col3 as acol3,a.col4 as acol4,a.col5 as acol5,b.col4 as
     bcol4,b.col5 as bcol5 from t1 a inner join t1 b on b.col1=a.col1 and b.col2=a.col2 and 
    b.col3=a.col3 and a.id<b.id 
      

  3.   

    with test as
    (
    select 1 a ,2 b,3 c ,'test1' d , 1 e from dual
    union all
    select 1 ,2,3,'test2',2 from dual
    )
    select * from test
    pivot
    (
     min(d)
     for e in (1 d1,2 d2)
    )