sql 降序查询问题
请问各位如何查询降序排序中排第二的数据?
例如
id name
1 a
2 b
3 c
4 d
5 e
按id降序查询后我需要去得id为4的数据,请问sql查询语句怎么写?
------解决方案--------------------select id,name from (select row_number()over(order by id desc) as px,* from tb)t where px=2
------解决方案--------------------select TOP 1 * from TB
where id not in(select top 1 id from TB order by id desc) order by id desc
------解决方案--------------------select top 1 * from (
select top 2 * from tb order by id desc
) a order by a.id asc