sql - 如何展示三个最年长的人
问题描述
我有这张桌子:
任务:显示三个最年长员工的名字、姓氏和年龄。
我知道我可以向最年长的雇主展示使用
WHERE birth_date=(SELECT MIN(birth_date);
但是如何展示 3 位最年长的员工呢?
解决方案
SELECT first_name, last_name, current_date - birth_date as age from employees ORDER BY age DESC LIMIT 3;
如果您对日级别差异很挑剔:
SELECT first_name, last_name, julianday('now') - julianday(birth_date) as age_in_days from employees ORDER BY age_in_days DESC LIMIT 3;