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

数据汇总筛选
表A
a b
2012-09-01 10
2012-09-02 5 
2012-10-01 2
2012-10-12 50

表B
c d e
1 2012-09-01 2012-10-10 
2 2012-10-11 2012-10-20

求表A列a在表B时间段d-e内的表A列b的汇总,结果
c d e 结果列
1 2012-09-01 2012-10-10 17
2 2012-10-11 2012-10-20 50

谢谢  
 

------解决方案--------------------
SELECT B.*,(SELECT SUM(B) FROM A WHERE A BETWEEN B.D AND B.E) AS SUMA FROM B