从与给定日期之前的日期关联的字段中找出总金额


Finding out the sum amount from fields that are associated with dates before a given date

我的数据库中有下表。现在我想从"金额"字段中找出与 04-01-2012 之前的日期关联的总金额。

id        Date            Amount
1      02-01-2012          500 
2      03-01-2012          500 
3      04-01-2012          500 
4      25-01-2012          500 
5      10-02-2012          500 
6      21-03-2012          500 

如果我手动计算,那么结果将是:500(日期:02-01-2012)+ 500(日期:03-01-2012)= 1000。

你能帮我解决mysql查询吗?

提前致谢:)

SELECT SUM(Amount) FROM your_table WHERE `Date` < DATE('04-01-2012')

这样的东西是最好的:

SELECT SUM(`Amount`) AS `Total` FROM `table` WHERE `Date` < DATE('2012-01-04')

将返回:

Total  
1000
Select Sum(Amount) `Total` From table where `Date` < DATE(`04-01-2012`);