php - mysql - Query by interval and or returning nothing -
i need select emails users table weekly_mail
(datetime) older 1 week or null , if user's points add more 10. it's not returning now.
points_plus table structure
id | user_id | points | date 1 62 5 2015-05-13 08:42:37 2 62 15 2015-05-14 03:12:32
query
$q = "select u.email, u.weekly_mail, sum(p.points) points users u left join points_plus p on u.id = p.user_id points > 10 , u.weekly_mail < now() - interval 1 week or u.weekly_mail = null group p.user_id"; $result = $this->db->mysqli->query($q); if (!$result) { printf("query failed: %s\n", $this->db->mysqli->error); exit; } $rows = array(); while($row = $result->fetch_row()) { $rows[]=$row; } $result->close(); return $rows;
check this:
$q = "select u.email, u.weekly_mail, sum(p.points) points users u left join points_plus p on u.id = p.user_id u.weekly_mail < (now() - interval 1 week) or u.weekly_mail null group p.user_id having sum(p.points) > 10";
Comments
Post a Comment