--> 测试数据: @T1
declare @T1 table (id int,scode varchar(9),sqty int)
insert into @T1
select 1,'s1' ,1 union all
select 2,'s2' ,2
--> 测试数据: @T2
declare @T2 table (id int,pcode varchar(9),pqty int,yid int)
insert into @T2
select 12,'p2',3,2 union all
select 13,'p3',4,2 
--> 测试数据: @T3
declare @T3 table (rcode varchar(9),rqty int,yid int)
insert into @T3
select 'r4',34,13 union all
select 'r5',35,13 union all
select 'r6',36,13select * from t1
left join t2
on t2.yid=t1.id
left join t3
on t3.yid=t2.id如何将结果集中t1,t2中的重复数据去掉,谢谢!

解决方案 »

  1.   

    重复数据空就好了,上面的结果集,就是一斜线,右上,左下都是NULL
    结果集贴不明白
       
      

  2.   


    with t
    as(
    select * from t2 a
    inner join t3 b
    on a.id=b.yid
    )
    select * from t1 a
    inner join t2 b
    on a.id=b.yid
      

  3.   

    select * from t1
    left join t2
    on t2.yid=t1.id
    left join t3
    on t3.yid=t2.id
    这个就是我想要的结果,但是想把这个结果集里边,T1,T2重复的数据用NULL,替换掉
      

  4.   

    inner join 是不对的,就是多表的left join ,但想把左表的重复数据用null表示。
    测试数据就是t1,t2,t3
    关联关系
    on t2.yid=t1.id
    on t3.yid=t2.id1          s1         1          NULL NULL NULL NULL NULL NULL NULL
    2          s1         2          2          p2         12         12         NULL NULL NULL
    2          s1         2          2          p3         13         13         13         r6         36        
    2          s1         2          2          p3         13         13         13         r4         34        
    2          s1         2          2          p3         13         13         13         r5         35      这结果中的,重复数据用null替换,  
      

  5.   

    1 s1 1 NULL NULL NULL NULL NULL NULL NULL
    2 s1 2 2 p2 12 12 NULL NULL NULL
             p3 13 13 13   r6 36   
                           r4 34   
                           r5 35要这个样子