Y
Y
yavis232021-04-22 11:30:13
PostgreSQL
yavis23, 2021-04-22 11:30:13

How to calculate the average value of cells with the same place of work?

Good afternoon, the essence of the task is

to Run a query that:
- Gets the titles of positions and the average salary for the position;
- the position must be related to management, i.е. contain the word Manager;
- the average salary should not be less than 10 thousand.

I display all the necessary positions, and the salary of all people for these positions, but it is impossible to calculate the average salary. Tell me which way to go

Select jobs.job_title, employees.salary
  FROM jobs, employees
  Where jobs.job_title Like '%Manager' AND employees.job_id=jobs.job_id

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-04-22
@rozhnev

For example like this:

SELECT 
  jobs.job_title, 
  AVG(employees.salary) average_salary
FROM 
  employees 
JOIN jobs ON employees.job_id = jobs.job_id
WHERE 
  jobs.job_title Like '%Manager'
GROUP BY jobs.job_title
HAVING AVG(employees.salary) > 10000;

PostgreSQL fiddle
And read something about JOIN and AGGREGATION FUNCTIONS

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question