可以参考下面的方法:
1、将查询的结果按照时间列从小到大排序,也就是正序排序,只取第一条就行
SELECT TOP 1 * FROM tb ORDER BY 时间列
2、另外可以使用子查询
SELECT * FROM tb WHERE 时间列=(SELECT MIN(时间列) FROM tb)
扩展资料:
SQL参考语句
AVG(字段名) 得出一个表格栏平均值
COUNT(*字段名) 对数据行数的统计或对某一栏有值的数据行数统计
MAX(字段名) 取得一个表格栏最大的值
MIN(字段名) 取得一个表格栏最小的值
Alter table tabname add primary key(col)添加主键
Alter table tabname drop primary key(col)删除主键
参考资料来源:百度百科-结构化查询语言
参考资料来源:百度百科-sql语句
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条)