T1,T2,T3 表里面的数据如下
T1 aa 1 2 3
T2 aa 11 22 33
T3 aa 111 222 333
我想结果是:
aa 1 2 3 11 22 33 111 222 333

解决方案 »

  1.   

    declare @t1 table(code varchar(4),c1 int,c2 int,c3 int)
    declare @t2 table(code varchar(4),c4 int,c5 int,c6 int)
    declare @t3 table(code varchar(4),c7 int,c8 int,c9 int)
    select a.*,b.c4,b.c5,b.c6,c.c7,c.c8,c.c9 
    from @t1 a,@t2 b,@t3 c 
    where a.code=b.code and a.code=c.code
      

  2.   

    没看明白,楼主把表T1、T2、T3分开来写~~~
      

  3.   

    declare @t1 table(code varchar(4),c1 int,c2 int,c3 int)
    declare @t2 table(code varchar(4),c4 int,c5 int,c6 int)
    declare @t3 table(code varchar(4),c7 int,c8 int,c9 int)
    insert into @t1 select 'aa',  1,  2,  3
    insert into @t2 select 'aa', 11, 22, 33
    insert into @t3 select 'aa',111,222,333select 
        a.*,b.c4,b.c5,b.c6,c.c7,c.c8,c.c9 
    from 
        @t1 a,@t2 b,@t3 c 
    where 
        a.code=b.code and a.code=c.code/*
    code c1          c2          c3          c4          c5          c6          c7          c8          c9          
    ---- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- 
    aa   1           2           3           11          22          33          111         222         333
    */
      

  4.   

    或者用inner join:
    declare @t1 table(code varchar(4),c1 int,c2 int,c3 int)
    declare @t2 table(code varchar(4),c4 int,c5 int,c6 int)
    declare @t3 table(code varchar(4),c7 int,c8 int,c9 int)
    insert into @t1 select 'aa',  1,  2,  3
    insert into @t2 select 'aa', 11, 22, 33
    insert into @t3 select 'aa',111,222,333select a.*,b.c4,b.c5,b.c6,c.c7,c.c8,c.c9 
    from @t1 a 
    inner join @t2 b on a.code=b.code   
    inner join @t3 c on a.code=c.code/*
    code c1          c2          c3          c4          c5          c6          c7          c8          c9          
    ---- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- 
    aa   1           2           3           11          22          33          111         222         333
    */
      

  5.   

    select a.col1, a.col2, a.col3, a.col4, b.col2, b.col3, b.col4, c.col2, c.col3, c.col4
    from T1 a join T2 b on a.col1 = b.col1
    join T2 c on a.col1 = c.col1
      

  6.   

    declare @t1 table(code varchar(4),c1 varchar(20),c2 varchar(20),,c3 varchar(20),)
    declare @t2 table(code varchar(4),c4 varchar(20),c5 varchar(20),c6 varchar(20))
    declare @t3 table(code varchar(4),c7 int,varchar(20),int,c9 varchar(20))
    insert into @t1 select 'aa',  1,  2,  3
    insert into @t2 select 'aa', 11, 22, 33
    insert into @t3 select 'aa',111,222,333select a.*,b.c4,b.c5,b.c6,c.c7,c.c8,c.c9 
    from @t1 a 
    inner join @t2 b on a.code=b.code   
    inner join @t3 c on a.code=c.code