简单的SQL查询语句。高手帮下忙呀。谢谢咯!!!

来源:百度知道 编辑:UC知道 时间:2024/05/24 15:37:20
比如有一列名称为“编号”。编号下面有1.2.3.4.....等数字 我要取最大值的下面这个数怎么写。也就是第2大的那个数字。。。。。搞了很久没有成功。晕了。。。

SELECT MAX(id) FROM 表 WHERE id < (SELECT MAX(id) FROM 表)

select
top 2 编号
from
table
order by 编号 desc //第二个就是了,然后自己加个SQL再倒下

或者
select
编号
from
table
where
编号<(select max(编号) from table) //这样直接就是了

select top 1 * from table1 where id in (select top 2 id from table1 order by id desc) order by id desc

反正就是先取出最大两行然后把最大两行倒序
也就是两次排序

首先,确定你的编号类型是数字?
那么

select top 1 编号 from 你的表 where 编号<max(编号)

方法很多啊 想的我都晕了 到底用哪个呢