比如有如下数据:表名:UserInfo
age name gender
13 aaa 男
16 bbb 女
12 ccc 妖
SQL:select * from UserInfo where age=(select min(age) from UserInfo)
结果:
age name gender
12 ccc 妖
查询出最小的年龄,然后查询该人的详细信息。
拙见。
select year month from 表格名where month=(select Min(month) from 表格名 where year=(select Min(year) from 表格名))
1.--大于等于所有(最大值)
select * from Apo_city
where city_id >=all (select city_id from Apo_city)
--小于等于所有(最小值)
select * from Apo_city
where city_id <=all (select city_id from Apo_city)
--2.
--降序取第一个(最大值)
select * from Apo_city
where city_id = (select top 1 city_id from Apo_city order by city_id desc )
--升序取第一个(最小值)
select * from Apo_city
where city_id = (select top 1 city_id from Apo_city order by city_id Asc )
--3.
--最大值
select Top 1 city_id from Apo_city order by city_id desc
--最小值
select Top 1 city_id from Apo_city order by city_id Asc
--4.
--最大值
With T
As
(
select *,ROW_NUMBER() over(order by city_id Desc) as id from Apo_city
)
select * from T where id=1
--最小值
With T
As
(
select *,ROW_NUMBER() over(order by city_id Asc) as id from Apo_city
)
select * from T where id=1
5.
--不小于任何一个(最大值)
select * from Apo_city
where not city_id < any (select city_id from Apo_city )
--不大于任何一个(最小值)
select * from Apo_city
where not city_id > any (select city_id from Apo_city )
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)