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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.