sql求和问题
表A
qxbm  sl
1     2
2     3
3     4
4     7
5     6表B
qxbm 
2
4
5求表A中qxbm存在于表B中的 sl的和 用一条sql语句

解决方案 »

  1.   

    select sum(a.sl) sl
    from a,b
    where a.qxbm=b.qxbm;
      

  2.   

    SELECT SUM(A.SL) SL FROM A INNER JOIN B ON A.QXBM=B.QXBM
      

  3.   

    select sum(nvl(sl,0))
    from a
    where exists (select qxbm from b where b.qxbm=a.qxbm)
      

  4.   

    select sum(sl)
    from A,B
    where tb1.qxbn=tb2.qxbm
      

  5.   

    select sum(a.sl) sl 
    from a,b 
    where a.qxbm=b.qxbm; 
      

  6.   


    select sum(nvl(a.sl,0)) as sl_sum
    from A a
    where exists (select 1 from B where b.qxbm=a.qxbm)
      

  7.   

    select sum(nvl(a.sl,0)) as sl_sum
    from A a
    where exists (select 1 from B b where b.qxbm=a.qxbm)