centerwork Posted July 30, 2008 Share Posted July 30, 2008 Here is what I am trying to do. In my table there is an Id column and a date column. The Id column will have reoccurring Ids. I need a query that will return the top five reoccurring Ids that occurred with in the last 30 days. Here is what I have so far: $date30 = time()-60*60*24*30; $query = "SELECT * FROM table WHERE date > $date30 ORDER BY DESC"; Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 30, 2008 Share Posted July 30, 2008 Assuming your date field is a unix timestamp, then it'll be something like this: $date = time()-60*60*24*30; $sql = "SELECT COUNT(*) as count,id FROM yourtable WHERE datefield > $date GROUP BY id ORDER BY count DESC LIMIT 5"; Quote Link to comment Share on other sites More sharing options...
centerwork Posted July 31, 2008 Author Share Posted July 31, 2008 Thank you, that worked great. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.