|
|
本页的SQL例句全部懂了,你的数据库开发所需知识就够用了 |
|
来源:yocin 时间:2012-2-17 14:20:01 栏目:技术支持 点击率:4815 |
--======子查询============ --在一个SQL语句中镶入另一个SQL语句教镶套查询,而被镶入的这个SQL语句就被江湖人称子查询。是处理多表操作的附加方法 --子查询也称内部查询,而包含子查询的Select语句被诚为外部查询,子查询自身可以包括一个或者多个子查询,也可以镶套任意数量的子查询
--使用in的子查询 select * from studio where cl_id in (select cl_id from class where cl_id>2) --使用 not in select * from studio where cl_id not in (select cl_id from class where cl_id>2)
--使用比较运算符的子查询 -- any 表示子查询中任意的值 all 表示子查询中的每个值 --使用any select * from class where cl_id>any(select cl_id from studio where st_age>30) --使用all select * from class where cl_id>all(select cl_id from studio where st_age>30)
--============一个分页的SQL语句======== select top 3 * from studio where st_id>all(select top 3 st_id from studio order by st_id) order by st_id
--使用 exists ,该关键字引入一个子查询的时候基本上是对数据进行一次是否存在的测试 --我们查询那些人所在的班级是编号为 1 的 select * from studio where exists(select cl_id from class where studio.cl_id=class.cl_id and class.cl_id=1) --使用 not exists select * from studio where not exists(select * from class where studio.cl_id=class.cl_id and class.cl_id=1) order by st_id
--基于查询生成新的表 select st_name into class_3 from studio where cl_id=3
--将数据批量插入一个表中 insert into class_3 select st_name from studio where cl_id=4
【 1 】 【 2 】 【 3 】 【 4 】 【 5 】 |
|
|
|