我正在努力让最年轻的工程师掌握所有信息(专栏)
SELECT
*,
EXTRACT( YEAR FROM MIN( AGE( NOW(), dob ) ) ) AS Youngest_Eng
FROM
employee
WHERE
Job = 'Engineer'
但它不起作用。我可以使用GROUP BY获取Job列,但我需要查看所有列。有没有办法做到这一点?
答案 0 :(得分:0)
按年龄排列应该只是前1名...但前1名不会显示平局...
select top 1 * from
employee
where job = 'Engineer'
order by
age
这应该显示领带
select * from
employee
where job = 'Engineer'
and age = (
select min(age) age from
employee
where job = 'Engineer'
)
答案 1 :(得分:0)
我会使用order by
和fetch first
:
SELECT e.*
FROM employee e
WHERE Job = 'Engineer'
ORDER BY dob DESC
FETCH FIRST 1 ROW ONLY;
无需实际计算年龄。最年轻的工程师拥有最大的dob
。
注意:FETCH FIRST 1 ROW ONLY
是ANSI标准;其他数据库可能使用其他语法,例如TOP (1)
或LIMIT
。