right/left outer join
具体怎么写请查help的join on

解决方案 »

  1.   

    select table1.a,table1.b,table1.c,isnull(table2.d,0) from table1 left join table2 on table1.a = table2.a
      

  2.   

    select A ,B,C isnull((select sum(D) from table2 where A=table1.A ),0) as D from table1
      

  3.   

    select table1.a,table1.b,table1.c,isnull(table2.d,0) from table1,table2 where table1.a *= table2.a
      

  4.   

    必须用外连接
    select  table1.A,B,C,D
    from table1,table2
    where table1.A=table2.A(*)保证正确!!
      

  5.   

    SELECT TABLE1.a AS Expr1, SUM(TABLE2.d) AS Expr2
    FROM TABLE1 RIGHT OUTER JOIN
          TABLE2 ON TABLE1.a = TABLE2.a
    GROUP BY TABLE1.a相信我,这个应该比较好,而且效率高,绝对可以用
      

  6.   

    select x.*,isnull(y.d,0) as d
    from table1 x left join (
      select a,sum(d) as d from table2 group by a
      ) as y
    on x.a=y.a
      

  7.   

    这个贴有意思,个个自夸!
    我给各位指出问题,不服的可以讨论:artmouse(艺术老鼠):
    1、left right搞反了
    2、最后格式和搂主要求不符
    3、假设你的写对了,也会出现d=null的,而不是0duxianghe(简单的人----delphi):
    1、你的外连接写法不是sql server的写法,也不是oracle的写法,好像是杂交的。
    2、假设你的写对了,也会出现d=null的,而不是0 yangxd(Goldenyxd) 
    正确!
      
    small_wei(small) 
    结果正确,效率可能差些。 sky_blue(老衲) 
    忘了sum
      

  8.   

    select M.a , M.B ,M.C  ,isnull(sum(N.D),0)
    From table1 M Left Join table2 N On M.a=N.a
    group by M.a,M.B.M.c
      

  9.   

    hehe
    I 服了 you  CSDNM(决定不当CSDN经理了)
      

  10.   

    to: CSDNM(决定不当CSDN经理了) 
    如果你不相信,请看 高等教育出版社的《数据库系统概论》第三版
    第105页。
    关于d=0 问题,可以在建立数据库的时候指定的,你只会说别人的,那你说怎么做?????