黑马视频-子查询
2015-11-14 20:36
281 查看
子查询:独立子查询 相关子查询select * from (select col1,col2 from Tbl) as Tb
平均分=select avg(score) from Tbs
4、子查询只能返回单个值 select * from Tbls where classId in (select classId from Tbs where classId='4' or classId='5')5、exists中包含的查询查到了结果则exists返回true,否则为false
select * from Tbl where exists( select * from Tbl1 where name='高二二班' and Tbl.classId=Tbl1.classId)
select * ,row_number() over (order by fid desc) as number from tb
20页,每页5条select * from ( select *,row_number() over (order by fid dsc ) as number from Tb
)as TbNew where tbNew.number between 19*5+1 and 20*5
row_number() 行号
select * ,count(*) from Tbl (错误)select * ,count(*) over () as 总条数 from Tbl
来自为知笔记(Wiz)
1、一个查询结果作为另一个查询的数据源 ,必须将子查询数据源 别名 as Tbs
select * from (select fname ,fage,fgender from MyStudent where fage between 18 and 25 and fgender='女') as Tbswhere fname like '%赵'2、作为列
select 最高分= select max(score) from Tbs, 最低分=select min(score) from Tbs,平均分=select avg(score) from Tbs
3、将查询结果作为查询条件
select * from TblStudent where tsclassid=(select tsclassid form TblClass where className ='高二二班')4、子查询只能返回单个值 select * from Tbls where classId in (select classId from Tbs where classId='4' or classId='5')5、exists中包含的查询查到了结果则exists返回true,否则为false
if(exists(select * from Tbl where 1<>1))begin
print '有结果'
end
elsebegin
print '无结果'
end
select * from Tbl where exists( select * from Tbl1 where name='高二二班' and Tbl.classId=Tbl1.classId)
select * ,row_number() over (order by fid desc) as number from tb
20页,每页5条select * from ( select *,row_number() over (order by fid dsc ) as number from Tb
)as TbNew where tbNew.number between 19*5+1 and 20*5
row_number() 行号
select * ,count(*) from Tbl (错误)select * ,count(*) over () as 总条数 from Tbl
来自为知笔记(Wiz)
相关文章推荐
- 信息安全系统设计基础第九章学习总结
- HDU 1677 Nested Dolls
- 26 Remove Duplicates from Sorted Array
- 606第十周周六赛 C - 吉哥系列故事――礼尚往来
- 107 Binary Tree Level Order Traversal II
- Frontier4.1简介
- css3学习过程----制作曲线阴影效果
- Leetcode好的微博
- Java异常捕获 跟踪异常的传播路径
- Java异常处理 finally用法
- ios程序员容易上手的服务器程序php入门【apache+php+mysql】开发环境搭建(一)
- java内存模型-续1
- ACM学习历程—HDU 5534 Partial Tree(动态规划)
- 101 Symmetric Tree
- 欢迎使用CSDN-markdown编辑器
- MFC总结(15) --- 实现图片移动 小火箭简单效果
- 231 Power of Two
- 110 Balanced Binary Tree
- EF部分字段更新,自动忽略null字段
- 一个简单的实现奇 偶判断的代码