pagegen Posted January 21, 2011 Share Posted January 21, 2011 Hi guys I hate a table which stores results for everydays page impressions example: table_result (id, campaign_id, clicks, date) How can i create a sql report which returns weekly SUM(clicks) Quote Link to comment https://forums.phpfreaks.com/topic/225206-weekly-sumclicks/ Share on other sites More sharing options...
BlueSkyIS Posted January 21, 2011 Share Posted January 21, 2011 You should not name a field using a MySQL reserved word, date. but if you do, you'll need to quote it... SELECT SUM(clicks) FROM impressions WHERE `date` >= '2011-01-01' AND `date`< '2001-01-08' Quote Link to comment https://forums.phpfreaks.com/topic/225206-weekly-sumclicks/#findComment-1163124 Share on other sites More sharing options...
PFMaBiSmAd Posted January 21, 2011 Share Posted January 21, 2011 And if you throw in a GROUP BY WEEK(date) term, the query will actually give you the sum for each week within the range of dates you specify. Quote Link to comment https://forums.phpfreaks.com/topic/225206-weekly-sumclicks/#findComment-1163129 Share on other sites More sharing options...
pagegen Posted January 21, 2011 Author Share Posted January 21, 2011 Ah nice one, Thank you guys Quote Link to comment https://forums.phpfreaks.com/topic/225206-weekly-sumclicks/#findComment-1163143 Share on other sites More sharing options...
Pikachu2000 Posted January 21, 2011 Share Posted January 21, 2011 'date' is one of the rare exceptions . . . MySQL permits some keywords to be used as unquoted identifiers because many people previously used them. Examples are those in the following list: ACTION BIT DATE ENUM NO TEXT TIME TIMESTAMP Quote Link to comment https://forums.phpfreaks.com/topic/225206-weekly-sumclicks/#findComment-1163161 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.