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. Link to comment https://forums.phpfreaks.com/topic/117262-solved-long-day-query-help/ 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"; Link to comment https://forums.phpfreaks.com/topic/117262-solved-long-day-query-help/#findComment-603471 Share on other sites More sharing options...
centerwork Posted July 31, 2008 Author Share Posted July 31, 2008 Thank you, that worked great. Link to comment https://forums.phpfreaks.com/topic/117262-solved-long-day-query-help/#findComment-604111 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.