Scooby08 Posted February 15, 2011 Share Posted February 15, 2011 If I have a table with info like so: id user_id type status created_on 1 1 a pending 2011-02-14 23:26:26 2 1 b pending 2011-02-14 23:26:26 3 1 c pending 2011-02-14 23:26:26 4 1 c pending 2011-02-14 23:26:26 5 1 a pending 2011-02-14 23:26:26 Would there be a way to count the total rows, while making the type 'c' values count as only one row? So really there would be only 4 rows counted here.. Is there something similar to the below out there that could work? SELECT * FROM table WHERE status = 'pending' GROUP BY type = 'c' Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/227713-group-by-particular-fields-value/ Share on other sites More sharing options...
bh Posted February 15, 2011 Share Posted February 15, 2011 Hi, first count the rows where type != 'c' (or if you want to more expects use "not in"), and after this method check whether type = 'c' row is exist or not... (in one query i think it would more expensive) Quote Link to comment https://forums.phpfreaks.com/topic/227713-group-by-particular-fields-value/#findComment-1174441 Share on other sites More sharing options...
fenway Posted February 17, 2011 Share Posted February 17, 2011 Yes, group by can take any valid expression. Quote Link to comment https://forums.phpfreaks.com/topic/227713-group-by-particular-fields-value/#findComment-1175748 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.