Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查mysql表中的年龄_Mysql_Sql_Mysql Workbench - Fatal编程技术网

检查mysql表中的年龄

检查mysql表中的年龄,mysql,sql,mysql-workbench,Mysql,Sql,Mysql Workbench,我是Mysql的新手,我需要帮助从horse表中查找10岁以上的马,该表包含“Born”和“Dead”列,仅在年份内,例如Born(1986)Dead(1998)。纯种马被视为在出生年份的1月1日出生。所以你只需要简单的减法就能得到正确的答案 select horse_name from horses where born < (year(current_date) - 10) and died is null; 选择马的名称 来自马 出生地

我是Mysql的新手,我需要帮助从horse表中查找10岁以上的马,该表包含“Born”和“Dead”列,仅在年份内,例如Born(1986)Dead(1998)。

纯种马被视为在出生年份的1月1日出生。所以你只需要简单的减法就能得到正确的答案

select horse_name
from horses
where born < (year(current_date) - 10)
  and died is null;
选择马的名称
来自马
出生地<(年份(当前日期)-10)
死亡是无效的;

将运算符改为“我猜您指的是年满10岁的马,而不仅仅是活着的马。如果ypu发布表格结构,这会有所帮助(输出
SHOW CREATE table table name
)。也请阅读以下内容:简单查询。我认为这属于StackOverflow。将其迁移到,因为它太简单,不需要DBA,而只需要基本的SQL编程技能。