select count(1) as value1 
from T_A 
select count(1) as value2 
from T_B 
select (sum(A.value1)+sum(B.value2)) from T_A A,T_B B

解决方案 »

  1.   

    select t1.* , (select count(1) from t_a t2 where t2.id = t1.id) + (select count(1) from t_b t3 where t3.id = t1.id)
    from t_c t1
      

  2.   

    那应该是视图吧。
    create view vw_T_C
    as
    select c.*,(isnull(a.value1,0) + isnull(b.value2,0)) as [value] 
    from T_C c 
      left join T_A a on a.id=c.id
      left join T_B b on b.id=c.id
    go
    select * from vw_T_C
      

  3.   

    比如:
    T_A   sid, *, JinE1
    T_B   sid, *, JinE2
    T_C   sid, *
    三个表并必然的关系。SQL语句出现的形式
               select sid, *, count(JinE1) + count(JinE2)
               from T_C
      

  4.   

    select *,isnull((select count(1) from T_A),0) + isnull((select count(1) from T_B))as value 
    from T_C 
      

  5.   


    select 
      c.sid,
      *,
      a.cnt+b.cnt as value
    from t_c c,
    (select count(JinE1) as cnt from T_A) as a,
    (select count(JinE2) as cnt from T_B) as b
      

  6.   

    select c.*,isnull((select count(1) from T_A a where a.sid=c.sid),0) + isnull((select count(1) from T_B b where b.sid=c.sid),0)as value 
    from T_C c
      

  7.   


    select t1.* , (select count(1) from t_a t2 where t2.sid = t1.sid) + (select count(1) from t_b t3 where t3.sid = t1.sid)
    from t_c t1如果可能存在不匹配的话,如楼上加isnull()
    select t1.* , isnull((select count(1) from t_a t2 where t2.sid = t1.sid),0) + isnull((select count(1) from t_b t3 where t3.sid = t1.sid),0)
    from t_c t1