1

我在数据库中有下表。我希望能够获得值列的总和,但仅基于日期。

+-------+---------+------------+
| 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 |
+-------+---------+------------+

谁能帮忙?

4

2 回答 2

2
Select id,sum(`value`) `value` , DATE(`date`) from table_name group by DATE(`date`);
于 2013-06-19T06:36:35.507 回答
0
SELECT ID, SUM(value), date FROM table_name GROUP BY date;
于 2013-06-19T06:42:25.940 回答