vikky
vikky

Reputation: 11

To sum values in a column based on date in another column and group it

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

Answers (2)

AllTooSir
AllTooSir

Reputation: 49432

Select id,sum(`value`) `value` , DATE(`date`) from table_name group by DATE(`date`);

Upvotes: 2

PythonIITD
PythonIITD

Reputation: 85

SELECT ID, SUM(value), date FROM table_name GROUP BY date;

Upvotes: 0

Related Questions