您的位置:首页 > 博客中心 > 数据库 >

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

时间:2022-03-14 03:50

子查询

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

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

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型)

热门排行

今日推荐

热门手游