注册 登录
编程论坛 SQL Server论坛

[求助]查询表中的某行数据(前提:不知道任何字段,只知道表名)

lhj2005 发布于 2007-10-11 20:15, 2817 次点击
比如:table_a
no. tag price
1 adidas 1000
2 nike 500
3 360 10000
4 不知道 5000
...


我如何直接获取第3行数据(前提:不知道任何字段,所以不能使用where)

请教!!!


24 回复
#2
purana2007-10-11 20:32
我想这是不行吧.
最起码也要有个id
#3
lhj20052007-10-11 20:38
select top 1 * from table_a不是可以查到第一行吗
有没有其他的查询方法???
#4
purana2007-10-11 20:50
你现在不是取第一条的问题.
#5
gggg0072007-10-12 08:36
用游标可以实现
#6
Kendy1234562007-10-12 09:12

楼上 不知道任何字段的情况下 用游标也实现不了

#7
volte2007-10-12 09:19
用游标能实现吗,你怎么去取数据
你不知道字段。

我想如果一个字段都不知道这个是比较难实现的。
#8
西风独自凉2007-10-12 09:26
在VB前台可實現。
Rs.open"select *from table_a",cn,3,2
if rs.RecordCount >=3 then
rs.MoveFirst
rs.MoveNext
rs.MoveNext
else
msgbox "數據不足3行或無數據"
end if
此時便是第三行的數據。。。
#9
sky_yang_sky2007-10-12 09:28
select top 3 IDENTITY(int, 1,1) AS ID,* into #qq from table
select top 1 * from #qq order by id desc
不過這樣多了一個字段id

[此贴子已经被作者于2007-10-12 9:29:21编辑过]

#10
purana2007-10-12 09:33
use Northwind
go
select id=identity(int,1,1),* into #t from Customers
--取第11条记录
select top 1 * from #t where id not in(select top 10 id from #t)
drop table #t
#11
purana2007-10-12 09:35
如果在VB里.
那直接用Move就可以了.
或者用AbsolutePosition去确定哪一条.
#12
西风独自凉2007-10-12 10:08
9樓方法可以
#13
gggg0072007-10-12 13:55
declare zzz_cursor scroll cursor
for
select * from table
open zzz_cursor
fetch absolute 3 from zzz_cursor
这样就可以显示第三行数据了
这里没用到列名吧?
#14
purana2007-10-12 14:01
那你测试过可以吗?
#15
purana2007-10-12 14:01

fetch 需要into到变量.

#16
gggg0072007-10-12 14:08
试过  是可以显示第三条的数据
#17
purana2007-10-12 14:14
好像确实可行.
#18
gggg0072007-10-12 14:20
[IMG]c:\桌面\未命名.bmp[/IMG][IMG]c:\桌面\未命名1.bmp[/IMG]
#19
sky_yang_sky2007-10-12 15:33
以下是引用gggg007在2007-10-12 13:55:51的发言:
declare zzz_cursor scroll cursor
for
select * from table
open zzz_cursor
fetch absolute 3 from zzz_cursor
这样就可以显示第三行数据了
这里没用到列名吧?

不錯,學習

#20
giant6112007-10-12 15:47
都好牛X
#21
volte2007-10-12 21:27

oracle中比较容易实现。oracle中是有个id的。

#22
purana2007-10-12 21:27
如果是这样.那MySQL更容易实现了.有个Limit
#23
bygg2007-10-13 14:17
LS的方法中有个id。
不是有个rowid吗
#24
lhj20052007-10-15 17:08
好复杂啊,怎么理解啊!
select id=identity(int,1,1),* into #t from Customers
#25
sky_yang_sky2007-10-16 09:29

在原表Customers的基礎上增加一個新的字段ID將其內容全部插入臨時表#t中

1