我无法显示每个部门最年轻的员工。
还有一个名为 的表department
,它简单地表示部门编号和部门名称。我也尝试过 WHERE EXISTS 子句,但没有运气。
SELECT emp_department_number,
emp_name,
MIN(TRUNC(((current_date - emp_dateofbirth)/(365.25)))) "age"
FROM employee
GROUP BY emp_department_number, emp_name
ORDER BY emp_department_number;
我也有这个,但它会产生相同的结果..
SELECT emp_department_number, emp_name, min(TRUNC(((current_date - emp_dateofbirth)/(365.25)))) "age" from employee
JOIN department
ON dpt_num=emp_department_number
WHERE EXISTS (select min(emp_dateofbirth) from employee)
GROUP BY emp_department_number, emp_name
order by emp_department_number;
EMP_DEPARTMENT_NUMBER EMP_NAME age
-------------- ------------------------------ ----------
1 Ramon, Emma 25
1 Tin, Rina 69
3 Mason, John 68
3 Roberson, Wayne 50
3 Zan, Shelis 51
7 Hockman, Ronnie 62
7 Lam, Annie 37
7 Smith, Ramon 60