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) 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' 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. 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 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 Link to comment https://forums.phpfreaks.com/topic/225206-weekly-sumclicks/#findComment-1163161 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.