select Target.T_Name,Target.T_Detail,count(tmp.[ID]) from
Target inner join 
(
select A.A_ID [ID],A.A_Name [Name] from A
union all
select B.B_ID [ID],B.B_Name [Name] from B
union all
select C.C_ID [ID],C.C_Name [Name] from C
) tmp
group by Target.T_Name,Target.T_Detail

解决方案 »

  1.   

    select [name],count(*) from (select A_Name [name] from A union all select b_Name from b union all select c_Name from c) tem where [name] in (select t_name from target) group by [name]
      

  2.   

    Select T_name,(select count(*) from 表A where A_name = a.T_name) + 
    (select count(*) from 表B where B_name = a.T_name)+
    (select count(*) from 表C where C_name = a.T_name) as Num
    from Target a
      

  3.   

    sorry!漏了一点。。select Target.T_Name,Target.T_Detail,count(tmp.[ID]) from
    Target inner join 
    (
    select A.A_ID [ID],A.A_Name [Name] from A
    union all
    select B.B_ID [ID],B.B_Name [Name] from B
    union all
    select C.C_ID [ID],C.C_Name [Name] from C
    ) tmp on tmp.[Name] = Target.T_Name
    group by Target.T_Name,Target.T_Detail
      

  4.   

    select Target.T_Name,Target.T_Detail,count(*) from
    Target join 
    (
    select A.A_Name [Name] from A
    union all
    select B.B_Name from B
    union all
    select C.C_Name from C
    ) tmp on Target.t_name=tmp.a_name
    group by Target.T_Name,Target.T_Detail
      

  5.   

    select a.T_Name,a.T_Detail,count(b.ID) from
    Target a join 
    (
    select A.A_ID ID,A.A_Name [Name] from A
    union all
    select B.B_ID,B.B_Name from B
    union all
    select C.C_ID,C.C_Name from C
    ) b
    on a.T_Name=b.[Name]
    group by a.T_Name,a.T_Detail
      

  6.   

    orselect T_Name,T_Detail,count(A_Name) from 
    ((
    select A_Name from A
    union all
    select B_Name from B
    union all
    select C_Name from C
    ) b 
    join Target a on a.a.T_Name=b.A_Name
    ) tem
    group by T_Name,T_Detail
      

  7.   

    问题解决,感谢各位热心帮助,Thx!