获取sql中某一行的行值?

牙签是竹子的 2010-03-27 10:27:00
表如下:

id name
22 张三
23 李四
...


在表中,第一行的值是id=22,name=张三

现在想实现是想取第二行的值,但是我并不知道里面的值,只知道要取第二行的值?

select * from 表 where ...?

where 条件怎么写?

...全文
1043 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
langfengxiaying123 2010-06-01
  • 打赏
  • 举报
回复
我也想知道答案呀
love_幸运儿 2010-03-28
  • 打赏
  • 举报
回复
要取某一行的值?
牙签是竹子的 2010-03-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ldslove 的回复:]
or



SQL code
select * from (
select *,ROW_NUMBER() over(order by getdate()) as rn from tb
) where rn=2
[/Quote]
Msg 156, Level 15, State 1, Line 2
关键字 'where' 附近有语法错误。
牙签是竹子的 2010-03-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ldslove 的回复:]
SQL code
select * from (
select *,ROW_NUMBER() over(order by id) as rn from tb
) where rn=2


???
[/Quote]
Msg 156, Level 15, State 1, Line 3
关键字 'where' 附近有语法错误。
--小F-- 2010-03-27
  • 打赏
  • 举报
回复
2000的话加个自增列
select id0=identity(int,1,1),* into #t from tb
select id,name from #t where id0=2
guguda2008 2010-03-27
  • 打赏
  • 举报
回复
我承认我迷茫了
--小F-- 2010-03-27
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 greatchao88 的回复:]
我是想去具体某一行的值,是哪一行并不确定
[/Quote]

那这个
select * from (
select *,ROW_NUMBER() over(order by getdate()) as rn from tb
) where rn=2
--小F-- 2010-03-27
  • 打赏
  • 举报
回复
select * from tb  where id=(select min(id) from tb where id>22)
牙签是竹子的 2010-03-27
  • 打赏
  • 举报
回复
我是想去具体某一行的值,是哪一行并不确定
htl258_Tony 2010-03-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 ws_hgo 的回复:]
你的是得到第一行的值了
在求第二行的值吗》
[/Quote]
如果是这样:
select top 1 * from 表 where id>22 order by id
newasoft 2010-03-27
  • 打赏
  • 举报
回复
用下列的句子。
SELECT * FROM table LIMIT 5,10; // 检索记录行 6-15
永生天地 2010-03-27
  • 打赏
  • 举报
回复
select top 2 * from tb
where id <>(select top 1 id from tb)
ws_hgo 2010-03-27
  • 打赏
  • 举报
回复
select top 1 * 
from
(
select top 2 * from tb order by id
) t
order by id desc
黄_瓜 2010-03-27
  • 打赏
  • 举报
回复
select top 1 * from 
(select top 2 * from tb order by 排序字段) a
order by 排序字段 desc
feixianxxx 2010-03-27
  • 打赏
  • 举报
回复
select *
from tb
where id=(select min(id) from tb where id>22)
ws_hgo 2010-03-27
  • 打赏
  • 举报
回复
你的是得到第一行的值了
在求第二行的值吗》
htl258_Tony 2010-03-27
  • 打赏
  • 举报
回复
select top 1 * 
from (select top 2 * from tb order by id) t
order by id desc
东那个升 2010-03-27
  • 打赏
  • 举报
回复
or


select * from (
select *,ROW_NUMBER() over(order by getdate()) as rn from tb
) where rn=2
东那个升 2010-03-27
  • 打赏
  • 举报
回复
select * from (
select *,ROW_NUMBER() over(order by id) as rn from tb
) where rn=2


???
zhengduan964532 2010-03-27
  • 打赏
  • 举报
回复

with romance as
(
select *,rownumber=row_number()over(order by getdate())
from table
)
select * from romance where rownumber=2
加载更多回复(3)

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧