Using two COUNT() functions in the query
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?