inbowns Posted December 3, 2011 Share Posted December 3, 2011 I was able to get my count to work that I posted in my previous post but I have a problem I would like the post to count everything but if there's a that is Yes in my column but if there all No I would also like it to display 0 in the same output something like this. Type Response = Yes Car 5 Truck 1 Bike 0 Walk 3 Swim 0 Flying 1 So the "0" should show that the database saw "No" and displayed a zero. Link to comment https://forums.phpfreaks.com/topic/252411-count-to-show-all-records/ Share on other sites More sharing options...
Pikachu2000 Posted December 4, 2011 Share Posted December 4, 2011 I don't follow. Link to comment https://forums.phpfreaks.com/topic/252411-count-to-show-all-records/#findComment-1294139 Share on other sites More sharing options...
Pandemikk Posted December 4, 2011 Share Posted December 4, 2011 Uhm I think I do... http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_if SELECT IF(response = 'Yes', COUNT(whatever you're counting), 0) Link to comment https://forums.phpfreaks.com/topic/252411-count-to-show-all-records/#findComment-1294231 Share on other sites More sharing options...
inbowns Posted December 4, 2011 Author Share Posted December 4, 2011 Uhm I think I do... http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_if SELECT IF(response = 'Yes', COUNT(whatever you're counting), 0) Thank you for your response I tried this it didn't work is there something I'm missing something? Do i need JOIN or UNION to make this work? Link to comment https://forums.phpfreaks.com/topic/252411-count-to-show-all-records/#findComment-1294289 Share on other sites More sharing options...
Pikachu2000 Posted December 4, 2011 Share Posted December 4, 2011 You need to better explain just what you're trying to accomplish. Some sample data, a table structure, and expected results would be helpful. Link to comment https://forums.phpfreaks.com/topic/252411-count-to-show-all-records/#findComment-1294349 Share on other sites More sharing options...
fenway Posted December 4, 2011 Share Posted December 4, 2011 You need SUM and IF: SUM( IF(expr,1,0) ) Link to comment https://forums.phpfreaks.com/topic/252411-count-to-show-all-records/#findComment-1294400 Share on other sites More sharing options...
inbowns Posted December 5, 2011 Author Share Posted December 5, 2011 You need SUM and IF: SUM( IF(expr,1,0) ) I guess this will work but i also need it to show if there's for example 3 "no" then the data it should return a zero but currently it doesn't show anything. Essentially i want a count of the "Yes" if there 10 "yes" i want that actual count and if there's a "No" it should give me a zero regardless of how many there are listed. I hope this is clear Link to comment https://forums.phpfreaks.com/topic/252411-count-to-show-all-records/#findComment-1294729 Share on other sites More sharing options...
awjudd Posted December 5, 2011 Share Posted December 5, 2011 SELECT Type, COUNT ( CASE Response WHEN 'Yes' THEN 1 ELSE NULL END ) AS ResponseCount FROM table ~awjudd Link to comment https://forums.phpfreaks.com/topic/252411-count-to-show-all-records/#findComment-1294759 Share on other sites More sharing options...
fenway Posted December 6, 2011 Share Posted December 6, 2011 It's all the same. Link to comment https://forums.phpfreaks.com/topic/252411-count-to-show-all-records/#findComment-1294777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.