一道面试题!

zhnzzy 2007-01-16 02:11:15
Let’s say we have a database with 1 one-column table. It contains 1000 same records. Could you please give at least 1 solution to help get records between line 5 and 7. No line number, row id or index etc
...全文
357 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zwlippi 2007-01-19
  • 打赏
  • 举报
回复
不一定对吧
在Oracle中rowid,SQL Server就不太清楚了
rainyubin 2007-01-16
  • 打赏
  • 举报
回复
mark
Zine_Alone 2007-01-16
  • 打赏
  • 举报
回复
--测试数据
Create Table Test
(
Col1 nvarchar(32)
)

insert into Test values('1')
insert into Test values('1')
insert into Test values('1')
insert into Test values('1')
insert into Test values('1')
insert into Test values('1')
insert into Test values('1')
insert into Test values('1')
insert into Test values('1')
insert into Test values('1')

--开始行
declare @RowStart int
select @RowStart=5
--结束行
declare @RowEnd int
select @RowEnd=7

declare @i int
declare @RowCount int

select @RowStart=@RowStart+1
select @RowCount=@RowEnd-@RowStart
select @i=0
declare my_cursor SCROLL cursor
for
select col1 from Test
--Open Cursor
open my_cursor

fetch ABSOLUTE @RowStart from my_cursor
while @i<@RowCount
begin
select @i=@i+1
fetch Next from my_cursor
end
close my_cursor
deallocate my_cursor
xyq1986 2007-01-16
  • 打赏
  • 举报
回复
这题考察的应该是取数据的方法吧,不是要结果
coowoo 2007-01-16
  • 打赏
  • 举报
回复
It contains 1000 same records.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
取第一条就是了,反正都一样
landy_shasha 2007-01-16
  • 打赏
  • 举报
回复
刚把题意翻出来,不好意思,呵呵
楼上真快
liujia_0421 2007-01-16
  • 打赏
  • 举报
回复
DataReader读出..

或者填充到一个DataTable中,然后取出5-7条..
Zine_Alone 2007-01-16
  • 打赏
  • 举报
回复
Mark
xyq1986 2007-01-16
  • 打赏
  • 举报
回复
select top 7 * from table
添充到DataReader,
int n=5;
while(n--)
reader.Read();
while(reader.Read())
现在就是要的了

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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