Jump to content

Count() to show all records


inbowns

Recommended Posts

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

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.