显示员工“杰克”被雇用后雇用的员工的详细信息

时间:2014-06-27 04:57:16

标签: sql select nested where

以下是显示员工“杰克”被聘用后雇用员工详情的代码

所有信息都在一张表中。

我的查询:

select e.employee_name, e.hiredate
from employees e 
where e.employee_hiredate > jack.hiredate;

3 个答案:

答案 0 :(得分:0)

要获得“杰克”表,您只需要加入:

select e.employee_name, e.hiredate 
from employees e
join employees jack on jack.employee_name = 'Jack'
where e.employee_hiredate > jack.hiredate;

或者,您可以使用子查询:

select e.employee_name, e.hiredate 
from employees e
where e.employee_hiredate > (select hiredate from employees where employee_name = 'Jack');

This article可以为您提供有关联接如何工作的更好解释,this article将对子查询进行一些解释。

答案 1 :(得分:0)

Select * 
from   employees e 
where  convert(date,e.employee_hiredate)  > (select convert(date,e.employee_hiredate) 
                                             from employees 
                                             where employee = 'jack'
                                            )

答案 2 :(得分:0)

由于您要选择仅与特定员工进行比较的记录,因此您可以使用子查询。

Oracle 中,您可以执行以下操作:

select e.employee_name, e.hiredate
from employees e 
where TRUNC(e.employee_hiredate) > (SELECT TRUNC(HIREDATE) FROM EMPLOYEES WHERE EMPLOYEE_NAME = 'Jack');