Mysql基础入门(五)子查询 | 您所在的位置:网站首页 › sql知道出生日期怎么查看年龄大小 › Mysql基础入门(五)子查询 |
文章目录
什么是子查询where 嵌套子查询简单版in嵌套查询some嵌套查询all嵌套查询exists嵌套查询
什么是子查询
有如下表,现要求编写sql语句,查看年龄比“李斯文”小的学生,要求显示这些学生的信息 ,红框中的学生是比李斯文年龄小的学生。 第一步:查询得到“李斯文”的出生日期 SELECT bornDate from student where studentName="李斯文" ; ->1993-07-03第二步:利用WHERE语句,筛选出生日期比“李斯文”大的学生 SELECT * from student where bornDate >'1993-07-03' ; 子查询方法 将第二步需要的1993-07-03,用第一步中查询的语句代替,代码如下: SELECT * from student where bornDate >(SELECT bornDate from student where studentName="李斯文") ; where 嵌套子查询 简单版 找出比“孙权”大的人 select name,age from person where age > ( select age from person where name = '孙权' )输出结果为 输出结果为 |
CopyRight 2018-2019 实验室设备网 版权所有 |