I'm currently working with a database containing the following schema:

Here are the tasks I'm required to carry out:

For task 1, I formulated the following query (inclusion of avg(salary) was for testing purposes):
select dname, count(*), avg(salary)
from department, employee
where dno = dnumber
group by dname having avg(salary)>30000;
giving the output:
DNAME COUNT(*) AVG(SALARY)
------------------------- ---------- -----------
Hardware 10 63450
Research 4 33250
Headquarters 1 55000
Administration 3 31000
Software 8 60000
Sales 14 40821.4286
However I can not figure out task two. **I'm required to have the same values, however only with the count of males but the same average as the previous query **. I tried the following statement:
select dname, count(*), avg(salary)
from department, employee
where dno = dnumber and (dno,sex) in (select dno, sex from employee where sex = 'M' )
group by dname having avg(salary)>30000;
Which resulted in the correct count value, but resulted in the departmental average salary for males, not males and females. As seen below:
DNAME COUNT(*) AVG(SALARY)
------------------------- ---------- -----------
Hardware 7 65785.7143
Research 3 36000
Headquarters 1 55000
Software 7 57285.7143
Sales 10 42150
Please note I have to do this using nested queries, not CASE.
Hope this makes sense, any help would be appreciated.
Thanks.