Reputation: 11
I have the following table in a database. I want to be able to get the sum of the value column but only based on the date.
+-------+---------+------------+
| ID | value | date |
+-------+---------+------------+
| 1 | 3 | 2011-12-22 |
| 1 | 2 | 2011-12-22 |
| 1 | 4 | 2011-12-22 |
| 1 | 2 | 2012-01-01 |
+-------+---------+------------+
which should be
+-------+---------+------------+
| ID | value | date |
+-------+---------+------------+
| 1 | 9 | 2011-12-22 |
| 1 | 2 | 2012-01-01 |
+-------+---------+------------+
can anyone help?
Upvotes: 1
Views: 2561
Reputation: 49432
Select id,sum(`value`) `value` , DATE(`date`) from table_name group by DATE(`date`);
Upvotes: 2