Reputation: 121
I have Table with 3 Columns, Column1 with Date and Column2 stores Points which is nothing but Some random Number between 1 to 9 and column 3 which have some unique email address in every cell.
Now I want to add the points grouped by date for last 5 days. That is if I have 3 rows for day one, 1 rows for day two, 3 rows for day 3 and 2 rows for day 4 & 5 I should get the sum of points of these 11 rows grouped by date as 5 rows for five days.
Input
Date Points Email
2012-07-01 5 [email protected]
2012-07-01 6 [email protected]
2012-07-01 2 [email protected]
2012-07-02 5 [email protected]
2012-07-03 8 [email protected]
2012-07-03 7
[email protected]
2012-07-03 1
[email protected]
2012-07-04 3 [email protected]
2012-07-04 2 [email protected]
2012-07-05 3 [email protected]
2012-07-05 9 [email protected]
Output
Date Points
2012-07-01 13
2012-07-02 5
2012-07-03 16
2012-07-04 5
2012-07-05 12
Please suggest me a MySQL query for the above.
Upvotes: 0
Views: 280
Reputation: 23135
You can do:
SELECT date, SUM(points) AS points
FROM tbl
WHERE date > CURDATE() - INTERVAL 5 DAY
GROUP BY date
Upvotes: 0