Last answered:

01 May 2023

Posted on:

27 Apr 2023

0

Count(salary) and gender

My understanding is that we are counting the number of either male or female salaries (depending on the task), but avg(salary) is calculated regardless of gender. Am I correct? If so, maybe it would be better to include count of all salaries as well so that the calculations are consistent and comparable?

2 answers ( 0 marked as helpful)
Posted on:

27 Apr 2023

0

Here is my solutuon:

with cte_salary as (
                        select 
                            avg(salary) as avg_salary,
                            count(salary) as count_salary
                        from
                            salaries)
select
    sum(case when s.salary<c.avg_salary then 1 else 0 end),
    count(s.salary),
    avg(count_salary)
from
    salaries s
join
    employees e on e.emp_no = s.emp_no and e.gender = 'M'
cross join cte_salary c;

Instructor
Posted on:

01 May 2023

0

Hi Eugenia!
Thanks for reaching out.


Yes, the average salary is calculated regardless of gender. So, we compare it with the females salaries.


Hope this helps.
Best,
Tsvetelin

Submit an answer