表A
no  amt  date
01   20  1996-01-04
02   15  1996-02-01
……表B
eno  no  eamt  date
0101 01  10  1996-01-10
0201 01  -5  1996-01-15
0301 01  -30 1996-02-09
0102 02  15  1996-02-02
0202 02  -10 1996-02-13
……
请问如何求1996-02-01以后的amt、eamt的和,sql语句。

解决方案 »

  1.   

    select a.no,sum(a.amt+b.eamt) from A a inner join B b on a.no=b.no
    where a.date>'1996-02-01' and b.date> '1996-02-01'
    group by a.no
      

  2.   


    select a.no,b.eamt,sum(a.amt) amt
    from a left join (select no,sum(eamt) eamt from b where date > '1996-02-01' group by no) b
       on a.no = b.no
    where a.date > '1996-02-01'
    group by a.no,b.eamt
      

  3.   

    select no,sum(amt) from
    (select no,amt from A where date > '1996-02-01'
     union all
     select no,eamt from B where date > '1996-02-01'
    ) group by no
      

  4.   

    select no,sum(amt) from
    (select no,amt from A where date > '1996-02-01'
     union all
     select no,eamt from B where date > '1996-02-01'
    ) t group by no
      

  5.   

    select
     a.no,b.eamt,sum(a.amt) as amt
    from
     a
     left join (select no,sum(eamt) eamt from b where date > '1996-02-01' group by no) b
    on
     a.no = b.no
    where
     a.date > '1996-02-01'
    group by
     a.no,b.eamt
      

  6.   

    请问,最后一句group by 前面的 "t"是什么意思?