Answer the question
In order to leave comments, you need to log in
How to write complex queries in sql?
There is such a scheme, according to it you need to make the following queries:
1)
Select employees of the American and European regions (AMERICA and EUROPE), who have at least 2 transfers by position. The selection should contain the full name of employees, the name of their current position and the number of transfers .
SELECT first_name, last_name, job_title, count()
FROM regions, employees, jobs
Where region_name = ‘AMERICA’ and ‘EUROPE’ and count() > 2
SELECT department_id
FROM employees
group by department_id
having count(*) >=3
Answer the question
In order to leave comments, you need to log in
1)
select bla.* from
(
select t1.first_name "f", t1.last_name "n", count(*) "c"
from employees t1
inner join job_history t2 on t2.employee_id = t1.employee_id
inner join departments t3 on t3.departments_id = t2.departments_id
inner join locations t4 on t4.location_id = t3.location_id
inner join countries t5 on t5.country_id = t4.country_id
inner join regions t6 on t6.region_id = t5.region_id
where t6.region_name in (' AMERICA', 'EUROPE')
group by t1.first_name, t1.last_name
) bla
where bla."c" > 2
"the number of transfers by position is at least 2" - it means that JOBS_HISTORY should contain at least two or three records for this employee, depending on how this table is filled. So JOIN with SELECT.
For the second task - see the functions MIN(), MAX(), SUM() and the same JOIN with SELECT from EMPLOYEES.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question