oracle pl/sql格式:
select x.f1, x.f2, sum(f3)
  from table1 x, table2 y
 where x.f1=y.f1 (+)
   and x.f2=y.f2 (+)
group by x.f1,x.f2;sql server t/sql或access格式:
select x.f1, x.f2, sum(f3)
  from table1 x left join table2 y
    on (x.f1=y.f1 and x.f2=y.f2)
 group by x.f1,x.f2;其它格式不知道

解决方案 »

  1.   

    一点小问题:access中引用别名要加as关键词
    select x.f1, x.f2, sum(f3)
      from table1 as x left join table2 as y
        on (x.f1=y.f1 and x.f2=y.f2)
     group by x.f1,x.f2;
      

  2.   

    select x.f2, y.f3
      from table1 x left join (select F1,F2,sum(f3) as F3 from table2 group by F1,F2) as y
        on (x.f1=y.f1 and x.f2=y.f2)
      

  3.   

    select t1.f2,t2.f3 from 
           (select distinct f2 from a)as t1 left join
            (select f2,sum(f3) from b group by f2)as t2 
           on t1.f2=t2.f2;弱水您好,怎么现在也跑到这边来了!
      

  4.   

    select a.f1,(a.f2,)sum(b.f3) from a left outer join b on a.f1=b.f1
    group by a.f1(,a.f2)
      

  5.   

    Select A.F2,SUM(B.F3) From A LEFT JOIN B ON A.F1=B.F1 AND A.F2=B.F2 GROUP BY A.F2
      

  6.   

    以上各位老兄的方法我都试了,但是都不灵,我用的是SQL Anywhere 5.0。麻烦各位再费费心。谢谢!
      

  7.   

    select f2,sum(f3) from b group by f2 
    union
    select f2,0 from a where not exists ( select * from b where a.f2=b.f2)
    order by f2
      

  8.   

    对了,我假设f3为整型,null就是0了
      

  9.   

    to superjj2002:
      你的方法可行,但是查询效率不太好,我测了一下:
    select f2,sum(f3) from b group by f2 
    union
    select f2,0 from a where not exists ( select * from b where a.f2=b.f2)
    order by f2比单一的:select f2,sum(f3) from b group by f2 
    速度上差2倍多。还有没有更好的方法?
      

  10.   

    SQL Anywhere 有没有外连接?
    查一下help