首页 > 数据库技术 > 详细

7、SQL基础整理(子查询)

时间:2014-12-15 17:10:57      阅读:254      评论:0      收藏:0      [点我收藏+]

子查询

(用来进行两表等之间的查询)

***括号里面的查询只能显示一个列的信息

select *from haha where age in (

select MAX(age) from haha where bumen = ‘销售部‘

)and bumen in (

select bumen from haha group by bumen having COUNT(*)>5 )

 

 

--练习:按年龄从小到大排序后第、、人的信息

select top 3 *from haha where code not in(

select top 5 code from haha order by age)

order by age

 

-----------分页--------------

select top 5*from haha where code not in(select top 10 code from haha)

 

----------一个表按照规定的条目数(5)能分多少页----------

select ceiling(COUNT(*)/5.0)from haha

(不能用5整型,为防止自动默认为int型)

7、SQL基础整理(子查询)

原文:http://www.cnblogs.com/wleaves/p/4165014.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!