Sql高级子查询

1.将一个sql语句的结果作为条件来判断:子查询
2. 子查询的语句,查询的列只允许一个
3.子查询的语句,如果使用=,>,<,<=,>=结果必须只有一行
4. 如果使用in,那么可以存多行

--查看年龄比“李斯文”大的学员 select* from stuinfo where stuAge>
(select stuAge from stulnfo where stuName=李斯
--查询出来李斯文的年龄
select stuAge from stulnfo where stuName='李斯文
--查看性别和“李斯文”一致的学员
select * from stulnfo where stuSex = (
select stuSex from stulnfo where stuName='李斯文);
--查询“李斯文”的性别
select * from stulnfo where stuName='李斯文'
--删除性别和“李斯文”一致的学员 delete from stuinfo where stuSex=(
select stuSex from stuinfo where stuName=李斯文

查询年龄最大的学生信息
--排序取第一
select top 1*from stuinfo order by stuAge desc;
查询最大的年龄
select max(stuAge) from stuinfo; 

 

 
 
posted @ 2022-06-10 17:10  LFL284  阅读(58)  评论(0)    收藏  举报