日期:2014-05-17  浏览次数:20586 次

求大神再赐于一SQL
A表
DYEARMONTH PK_CORP CWAREHOUSEID CINVENTORYID CINVBASID DATEIN DATEOUT
2012-02 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP 10 0
2012-02 1002 1002F8100000000003ZB 0001F810000000006G5Z 0001F8100000000066IP 7 0
2012-04 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP 25 10
2012-05 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP 0 3
2012-07 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP 0 3
2012-07 1002 1002F8100000000003ZB 0001F810000000006G5Z 0001F8100000000066IP 13 10
2012-08 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP 0 9
2012-09 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP 15 2
2012-10 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP 0 2
2012-10 1002 1002F8100000000003ZB 0001F810000000006G5Z 0001F8100000000066IP 10 0
2012-11 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP 0 3
2012-11 1002 1002F8100000000003ZB 0001F810000000006G5Z 0001F8100000000066IP 0 8
2012-12 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP 0 3


B表
DYEARMONTH PK_CORP CWAREHOUSEID CINVENTORYID CINVBASID QICHU
2012-01 1002 1002F8100000000003ZB 0001F810000000006G5Z 0001F8100000000066IP 7
2012-01 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP 10
2012-03 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP 15
2012-04 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP -3
2012-06 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP -3
2012-06 1002 1002F8100000000003ZB 0001F810000000006G5Z 0001F8100000000066IP 3
2012-07 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP -9
2012-08 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP 13
2012-09 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP -2
2012-09 1002 1002F8100000000003ZB 0001F810000000006G5Z 0001F8100000000066IP 10
2012-10 1002 1002F8100000000003ZB 0001F810000000006G5Z 0001F8100000000066IP -8
2012-10 1002 1002F8100000000003ZA 0001F810000000006G5Z 0001F8100000000066IP -3
2012-11 1002 1002F8100000000003ZB 0001F810000000006G5Z 0001F8100000000066IP 7

两表关键,应该A left join B
现在,如果B.DYEARMONTH<A.DYEARMONTH,则将B表的qichu值汇总放入A表
如A表的2012-02 qichu应该是分CWAREHOUSEID,为对应两条
2012-02   1002F8100000000003ZA   10
2012-02   1002F8100000000003ZB   7
2012-04   1002F8100000000003ZA    10+15=25
2012-05.。。。。
2012-07   1002F8100000000003ZA    10+15+(-3)=19
2012-07   1002F8100000000003ZB    7+3=10
依次下去,

求大神解答,非常感谢!!!
注意是oracle数据!!