bugcoder Posted August 3, 2011 Share Posted August 3, 2011 hi everybody i have this query SELECT count(*) FROM `journal_entries` WHERE `created` BETWEEN '2011-07-01 00:00:00' AND '2011-08-03 00:00:00' AND `user_id` = 8; one user can add more than one journal entry per day. I just want to consider one entry per day. if there is one entry, it should be counted in count(*) else not. can i do it just with mysql? Quote Link to comment https://forums.phpfreaks.com/topic/243682-if-else-in-mysql-query/ Share on other sites More sharing options...
Muddy_Funster Posted August 3, 2011 Share Posted August 3, 2011 I'm not sure I follow. Do you want one count per day, one count per user, or one count per user per day? None of which really fit with what you are currently using in your where clause. Quote Link to comment https://forums.phpfreaks.com/topic/243682-if-else-in-mysql-query/#findComment-1251139 Share on other sites More sharing options...
bugcoder Posted August 3, 2011 Author Share Posted August 3, 2011 e.g if date range is for 7 days and user added 15 journal entries but out of 7 days, one day he didn't add any entry. then result should be 6. i.e we should not bother how many entries he did on one day. if he did even ten entries on one day it should be counted as 1 count. I hope im able to clear my point... :-\ Quote Link to comment https://forums.phpfreaks.com/topic/243682-if-else-in-mysql-query/#findComment-1251157 Share on other sites More sharing options...
kickstart Posted August 3, 2011 Share Posted August 3, 2011 Hi Something like this maybe SELECT COUNT(DISTINCT DATE(created)) FROM `journal_entries` WHERE `created` BETWEEN '2011-07-01 00:00:00' AND '2011-08-03 00:00:00' AND `user_id` = 8; All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/243682-if-else-in-mysql-query/#findComment-1251165 Share on other sites More sharing options...
bugcoder Posted August 3, 2011 Author Share Posted August 3, 2011 SELECT COUNT(DISTINCT DATE(created)) FROM `journal_entries` WHERE `created` BETWEEN '2011-07-01 00:00:00' AND '2011-08-03 00:00:00' AND `user_id` = 8; exact result....Thanks a lot...... Quote Link to comment https://forums.phpfreaks.com/topic/243682-if-else-in-mysql-query/#findComment-1251172 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.