запрос в sql

SQL-запрос
Дата: 16.10.2015 06:22:26
Необходимо вывести фамилии сотрудников, имеющих одного или более сотрудников их отдела с более поздней датой найма, но с более высоким окладом.

Пытался сделать, но у меня скорее всего ошибки:
select distinct e.last_name
from hr.employees e, hr.employees b
where e.department_id=b.department_id AND
e.hire_date < any ( select hire_date
from hr.employees 
where e.department_id=department_id)
AND
e.salary < any ( select salary
from hr.employees
where e.department_id=department_id);
Be or not to be...
Дата: 16.10.2015 06:36:04
select distinct e.last_name
  from hr.employees e, hr.employees b
 where e.department_id = b.department_id
   and exists (select 1
          from hr.employees e2
         where e2.department_id = e.department_id
           and e2.hire_date > e.hire_date
           and e2.salary > e.hire_date)
SQL-запрос
Дата: 16.10.2015 06:47:33
Be or not to be...
select distinct e.last_name
  from hr.employees e, hr.employees b
 where e.department_id = b.department_id
   and exists (select 1
          from hr.employees e2
         where e2.department_id = e.department_id
           and e2.hire_date > e.hire_date
           and e2.salary > e.hire_date)


Спасибо. У Вас только опечатка в конце: and e2.salary > e.salary.
Выдало 68 строк (всего 107), точно верно все?)
Be or not to be...
Дата: 16.10.2015 06:54:37
SQL-запрос,

Опечатка - да. А верно ли - я не знаю, вам виднее
Be or not to be...
Дата: 16.10.2015 06:58:12
select distinct e.last_name
  from hr.employees e[s], hr.employees b[/s]
 where [s]e.department_id = b.department_id[/s]
   [s]and[/s] exists (select 1
          from hr.employees e2
         where e2.department_id = e.department_id
           and e2.hire_date > e.hire_date
           and e2.salary > e.hire_date)


Ну вот так, конечно.. Ваше наследие было мной упущено
SQL-запрос
Дата: 16.10.2015 07:08:05
Be or not to be...
select distinct e.last_name
  from hr.employees e[s], hr.employees b[/s]
 where [s]e.department_id = b.department_id[/s]
   [s]and[/s] exists (select 1
          from hr.employees e2
         where e2.department_id = e.department_id
           and e2.hire_date > e.hire_date
           and e2.salary > e.hire_date)


Ну вот так, конечно.. Ваше наследие было мной упущено


Эмм... не понял) Вы там выделить егами что то хотели, где ?
SQL-запрос
Дата: 16.10.2015 07:11:11
Если убрать то, что между тегами, то результат тот же
ArtNick
Дата: 16.10.2015 10:01:57
SQL-запрос,
прочитай про аналитические функции
Moss
Дата: 16.10.2015 10:15:39
как по мне то этого достаточно
select distinct e.id, e.last_name
  from hr.employees e
 where
   exists (select 1
              from hr.employees e2
               where e2.department_id = e.department_id
                  and e2.hire_date > e.hire_date
                  and e2.salary > e.salary)
ArtNick
Дата: 16.10.2015 10:46:54
with t as
(select 1 dep, sysdate-2 hire_date, 500 salary, 'Smith' name from dual
 union all
 select 1 dep, sysdate-1 hire_date, 999 salary, 'Smith1' name from dual
 union all
 select 1 dep, sysdate-1 hire_date, 1000 salary, 'Smith2' name from dual)
select name
 from
  (select name, salary,dep,
           max(salary) over (partition by dep order by hire_date desc, salary asc rows between unbounded preceding and current row) best_salary
    from t)
 where salary<best_salary