如何写SQL? 
表A 
ID Name 
1 壹 
2 贰 
3 叁 
4 肆 
5 伍 
6 陆 
7 七 
8 捌 
9 九 
表B 
ID Bname 
1 Ⅰ 
2 Ⅱ 
4 Ⅳ 
5 Ⅴ 
6 Ⅵ 表C 
ID Cname 
3 NULL 
7 Ⅶ 
8 Ⅷ 
9 Ⅸ 用SQl写,结果如下: 
1 壹 Ⅰ 
2 贰 Ⅱ 
3 叁 NULL 
4 肆 Ⅳ 
5 伍 Ⅴ 
6 陆 Ⅵ 
7 七 Ⅶ 
8 捌 Ⅷ 
9 九 Ⅸ 

解决方案 »

  1.   

    select * From (
    select a.id,a.name,b.Bname  from a left join b on  a.id =b .id  
    union all
    select a.id,a.name,b.Cname from a left join c on c.id =a.id)
    d order by id
      

  2.   

    declare @tA table (ID int,cName nvarchar(20))
    declare @tB table (ID int,cName nvarchar(20))
    declare @tC table (ID int,cName nvarchar(20))
    insert into @tA select 1,'一'
    insert into @tA select 2,'二'
    insert into @tA select 3,'三'
    insert into @tA select 4,'四'
    insert into @tA select 5,'五'
    insert into @tA select 6,'六'
    insert into @tA select 7,'七'
    insert into @tA select 8,'八'
    insert into @tA select 9,'九'
    insert into @tB select 1,'Ⅰ'
    insert into @tB select 2,'Ⅱ'
    insert into @tB select 4,'Ⅳ'
    insert into @tB select 5,'Ⅴ'
    insert into @tB select 6,'Ⅵ'
    insert into @tC select 3,null
    insert into @tC select 7,'Ⅶ'
    insert into @tC select 8,'Ⅷ'
    insert into @tC select 9,'Ⅸ'
    select * from @tA
    select * from @tB
    select * from @tCselect A.ID,A.cName,E.cName
    from @tA A
    left join (select ID,cName from @tB
    union all
       select ID,cName from @tC) as E
    on (A.ID=E.ID)
      

  3.   

    declare @tA table (ID int,aName nvarchar(20))
    declare @tB table (ID int,bName nvarchar(20))
    declare @tC table (ID int,cName nvarchar(20))
    insert  @tA select 1,'壹'union all
                select 2,'贰'union all
                select 3,'叁'union all
                select 4,'肆'union all
                select 5,'伍'union all
                select 6,'陆'union all
                select 7,'七'union all
                select 8,'捌'union all
                select 9,'九'
    insert into @tB select 1,'Ⅰ'union all      
                    select 2,'Ⅱ'union all
                    select 4,'Ⅳ'union all
                    select 5,'Ⅴ'union all
                    select 6,'Ⅵ'
    insert into @tC select 3,null union all
                    select 7,'Ⅶ' union all
                    select 8,'Ⅷ' union all
                    select 9,'Ⅸ'select aname,bname From @ta a left join (select *from @tb union all select *From @tc) b on a.id=b.id
      

  4.   

    SQL Server2005高端培训视频,循序渐进,历时半年通过3大分系列的46次课程,让你完全掌握SQL Server2005.
    同Visual Studio 2005以及Microsoft .NET集成的开发特性,通过实例由浅入深的帮助您掌握这些看似难懂的技术。
    http://auction1.taobao.com/auction/item_detail-0db2-512881e1a3aab7111ccf190b0068536d.jhtml