SQL query to pull multiple entries with same user_id

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!

Answers


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

Need Your Help

Javascript prompt/textbox only numbers

javascript html css

Hey guys I'm just learning javascript, I have some html and css background though.

“Like” facebook button in wpf application

c# wpf facebook

I am developing wpf application and I have a like button that contains the image and number of likes.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.