0

I have the following table in my database. Now what I want to find out is the total sum amount that are associated with dates before 04-01-2012 from the field "amount".

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 

If I calculate it manually then the result would be: 500( Date: 02-01-2012)+ 500 (Date: 03-01-2012)= 1000.

Would you please kindly help me with the mysql query?

Thanks in Advance :)

4

3 回答 3

2
SELECT SUM(Amount) FROM your_table WHERE `Date` < DATE('04-01-2012')
于 2012-04-06T14:14:55.697 回答
1
Select Sum(Amount) `Total` From table where `Date` < DATE(`04-01-2012`);
于 2012-04-06T14:17:07.960 回答
1

像这样的东西是最好的:

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

将返回:

Total  
1000
于 2012-04-06T14:18:13.827 回答