Jump to content

Multipule count()'s in one query


truegilly

Recommended Posts

Hi Guys  :-*

 

Im using MYSQL with PHP and normally if i need to combine the outputs, create multiple MYSQL query's and add the results together.

 

I was wondering if it is possible using a single query to count different data thats in the same row of a table. The example below counts the number of times green in in the Actual_Colour field.

 

mysql> SELECT COUNT(*) FROM tornado_node WHERE Actual_Colour = 'green';
+----------+
| COUNT(*) |
+----------+
|        5 | 
+----------+
1 row in set (0.00 sec)

 

All very simple.

 

If i wanted to produce the same thing that also counted red and blue values that are in the Actual_Colour field do i have to create multiple querys or can it be done on a single line of SQL code?  ???

 

what i was hoping was to produce an output like this this below...

 

+----------++----------++----------+

|    Red    ||  green    ||    Blue    |

+----------++----------++----------+

|        5    ||      6      ||      2      |

+----------++----------++----------+

 

i could then in PHP set this as an associated array.

 

thank you for any help  ;)

 

Truegilly  :D

 

Link to comment
https://forums.phpfreaks.com/topic/46059-multipule-counts-in-one-query/
Share on other sites

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.