Skip navigation links

MySQL Forums :: Newbie :: Using two COUNT() functions in the query


Advanced Search

Using two COUNT() functions in the query
Posted by: Dmitry Piramidin ()
Date: November 03, 2009 01:56PM

Hi, all,

I have the table, named `test`, with structure like this:

| id | dept_id | gender | name |

every record in this table means one employee of department of the company. `dept_id` is the id of department, where employee works. `gender` = 1 when employee is male, 2 - when employee is female. For example, we have the following data in the table:

1, 1, 1, 'Brian'
2, 1, 2, 'Mary'
3, 1, 1, 'John'
4, 2, 2, 'Elizabeth'

How can I retrieve males and females count grouped by department? Here is the structure of the result:

| dept_id | males | females |

In our example result is supposed to be
1, 2, 1
2, 0, 1

I need to retrieve this data in one query, how can I do that?

Options: ReplyQuote


Subject Written By Posted
Using two COUNT() functions in the query Dmitry Piramidin 11/03/2009 01:56PM
Re: Using two COUNT() functions in the query Paul Svirin 11/03/2009 03:14PM
Re: Using two COUNT() functions in the query Chad Bourque 11/03/2009 03:47PM
Re: Using two COUNT() functions in the query Paul Svirin 11/03/2009 04:42PM


Sorry, only registered users may post in this forum.