views:

54

answers:

1

I have a table that contains id, created, user_id.

I'm wondering if there is a query that'll return all unique user_ids that have more than one entried created within the last week. I started with:

$query = "SELECT distinct user_id FROM task where created >= '" . date("Y-m-d", strtotime("-1 week", strtotime($date))) . " 00:00:00' and created <= '" . $date . " 23:59:99'"

This works for returning ALL distinct results, but I need to only grab those that have more than 1 entry in the last week.

Thanks!

A: 
SELECT user_id  FROM task
where created >= '" . date("Y-m-d", strtotime("-1 week", strtotime($date))) . " 00:00:00' 
 and created <= '" . $date . " 23:59:99'
 group by user_id
 having count(*) > 1
Dayton Brown
Amazing! Thanks
Ian Silber