I have a table like below:
uid nid points date reason
36 116 2 2012-08-28 11:52:12 session
31 110 2 2012-08-23 15:47:47 session
36 115 2 2012-08-27 11:52:48 session
as u can see uid is not unique, it can be repeated. What i need is to select sum of points for every id between date(30 days before). For example: sum of uid36 = to 4.
What i have tried:
$start_time = mktime(0, 0, 0, $today["mon"], ($today["mday"] - 30), $today["year"]);//30 days before
$end_time = time();
$query = db_query("SELECT uid,sum(points), date FROM users_history WHERE date BETWEEN '$start_time' AND '$end_time'");
but how to select for every id
You need
GROUP BY uid, anddateis meanless in your query if you are using aggregate functionSUM.And if there is no future date, then you only need