给出严格比任何住在伦敦的雇员年龄大的雇员的名字.?

  • 本文关键字:任何住 伦敦 mysql
  • 更新时间 :
  • 英文 :


问题基于北风数据库。

对于上面的问题,我试图找到答案,但我得到零行

select FirstName,LastName from employees
where City and BirthDate <
(
Select min(BirthDate) from employees where City='London'
);

删除City后

输出如下所示,有3行

但是从表中,如果我们看到一行缺少员工名Laura callahan,她比id为7和9的员工年龄大

员工表

去掉WHERE City AND BirthDate < (...)中的City

它将City视为布尔值,这需要将其转换为数字。除非城市以数字开头,否则它将转换为0,即FALSE,因此组合条件失败。

select FirstName,LastName from employees
where BirthDate <
(
Select min(BirthDate) from employees where City='London'
);

您需要使用max,因为min返回最老的日期。所以为了得到比伦敦员工年龄大的人的名单,他们的年龄应该比伦敦最年轻的人大。因此,您需要使用max

select FirstName,LastName
From employees
where BirthDate < (
Select max(BirthDate) from employees
where City='London'
);

相关内容

最新更新