首页 > 代码库 > 子查询
子查询
方法一 示例1变量版
use xuexioa --切换到xuexiao的数据库
declare @no int --声明一个整型局部变量@no
select @no=stuNo from student where stuName=‘张三‘ --查询出张三的学号赋值给@no
select*from student where stuNo>@no --查询出学号比张三的学号大的学生
方法二 示例2子查询版
select*from student where stuNo> --查询出比张三学号大的学生
(select stuNo from student where stuName=‘张三‘) --小括号中子查询:查询张三的学号
--子查询语句必须防止在一对圆括号内,外面的查询成为父查询,括号中的查询称为子查询
--执行时,先执行子查询部分,求出子查询部分的值,在执行整个父查询,返回最后的结果
--子查询作为where条件的一部分,还可以和update,insert,delete一起使用
子查询
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。