我在数据库中有以下表格。我希望能够获得值列的总和,但仅基于日期。
+-------+---------+------------+
| ID | value | date |
+-------+---------+------------+
| 1 | 3 | 2011-12-22 |
| 1 | 2 | 2011-12-22 |
| 1 | 4 | 2011-12-22 |
| 1 | 2 | 2012-01-01 |
+-------+---------+------------+
应该是
+-------+---------+------------+
| ID | value | date |
+-------+---------+------------+
| 1 | 9 | 2011-12-22 |
| 1 | 2 | 2012-01-01 |
+-------+---------+------------+
任何人都可以帮忙吗?
答案 0 :(得分:2)
Select id,sum(`value`) `value` , DATE(`date`) from table_name group by DATE(`date`);
答案 1 :(得分:0)
SELECT ID, SUM(value), date FROM table_name GROUP BY date;