cooldude832 Posted January 5, 2008 Share Posted January 5, 2008 I want to query my User contributions tables and return results like Post in last day: 15 Post in last week: 20 Post in last month: 100 Post in last year: 10000 Can I do this via one query if my table is like Posting PostID UserID PostDate Post etc. I don't know how to do the multiple limiting "wheres" on the selects. Link to comment https://forums.phpfreaks.com/topic/84571-solved-multiple-where-commands-on-a-select/ Share on other sites More sharing options...
fenway Posted January 5, 2008 Share Posted January 5, 2008 I guess you could have a SUM with an IF () condition for each one. Link to comment https://forums.phpfreaks.com/topic/84571-solved-multiple-where-commands-on-a-select/#findComment-430927 Share on other sites More sharing options...
cooldude832 Posted January 5, 2008 Author Share Posted January 5, 2008 can you show me an example would I do something <?php $userid = "15"; $oneweek = date("Y-m-d G:i:s", strtotime("-7 Days")); $q = "Select SUM(if(Post_Date >= '".$oneweek."')Posting_Table.Post_date) as `One_week` From `Posting_Table` Where Userid = '".$userid."'"; ?> I never done a mysql if Link to comment https://forums.phpfreaks.com/topic/84571-solved-multiple-where-commands-on-a-select/#findComment-430931 Share on other sites More sharing options...
Barand Posted January 5, 2008 Share Posted January 5, 2008 <?php $q = "SELECT SUM(IF(Post_date > NOW() - INTERVAL 1 DAY, 1, 0)) AS lastday , SUM(IF(Post_date > NOW() - INTERVAL 7 DAY, 1, 0)) AS lastweek , SUM(IF(Post_date > NOW() - INTERVAL 1 MONTH, 1, 0)) AS lastmonth , SUM(IF(Post_date > NOW() - INTERVAL 1 YEAR, 1, 0)) AS lastyear FROM Posting_Table WHERE Userid = '$userid' "; Link to comment https://forums.phpfreaks.com/topic/84571-solved-multiple-where-commands-on-a-select/#findComment-431080 Share on other sites More sharing options...
cooldude832 Posted January 5, 2008 Author Share Posted January 5, 2008 Thanks, I just let php do the work on this one, but I'll try this one later probably a way better choice than php cause I am drawing the whole date out and comparing it. Link to comment https://forums.phpfreaks.com/topic/84571-solved-multiple-where-commands-on-a-select/#findComment-431306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.