aprilleocean
aprilleocean

Reputation: 121

Mysql Group By Date

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

Answers (5)

A A Nayak
A A Nayak

Reputation: 43

select Date,sum(Points) from my_table group by Date;

Upvotes: 1

Shameem
Shameem

Reputation: 317

select `Date`,sum(`Points`) from my_table group by `Date` Limit 5;

Upvotes: 1

Zane Bien
Zane Bien

Reputation: 23135

You can do:

SELECT date, SUM(points) AS points
FROM tbl
WHERE date > CURDATE() - INTERVAL 5 DAY
GROUP BY date

Upvotes: 0

Joe G Joseph
Joe G Joseph

Reputation: 24116

select [Date],SUM(Points)
from myTable1
group by [Date]

Upvotes: 0

manurajhada
manurajhada

Reputation: 5390

select `Date`,sum(`Points`) from my_table group by `Date`;

Upvotes: 2

Related Questions