Mysql基础入门(五)子查询 您所在的位置:网站首页 sql知道出生日期怎么查看年龄大小 Mysql基础入门(五)子查询

Mysql基础入门(五)子查询

2024-07-15 23:42| 来源: 网络整理| 查看: 265

文章目录 什么是子查询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 = '孙权' )

输出结果为 在这里插入图片描述

in嵌套查询 找出魏国的人 select name from person where countryid in ( select countryid from country where countryname = '魏国' )

输出结果为 在这里插入图片描述

some嵌套查询 语法 { =||!=|>|>=|!>||


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有