|
sql="select * from student order by mark desc"
set Rf=Server.CreateObject("ADODB.Recordset")
Rf.open sql,conn,1,1
i=0
do while not Rf.eof
i=i+1
if Rf("name")="me" then
j=i
exit do
end if
Rf.movenext
loop
你的排名是:<%=j%>
我发现当table越来越多record的时候,速度越来越慢.
是不是有什么很好的思路可以解决这个问题? |
|
|
|
|
|
|
|
发表于 22-4-2005 10:25 AM
|
显示全部楼层
你的 looping 是属于 sequential search。
由于你的资料已排列好,试一试做一个 Quick Search 的 routine ! |
|
|
|
|
|
|
|
发表于 22-4-2005 10:38 AM
|
显示全部楼层
运用 MSSQL 的 stored procedure 就可以了, 那样只会输出你的排名, 你就不需要在你的 code 里 loop.
CREATE PROCEDURE [SP_OrderCheck]
AS
DECLARE @NAME VARCHAR (20)
DECLARE @ROWCOUNT INT
SET @ROWCOUNT = 0
DECLARE CUR_COUNT CURSOR
FOR SELECT name FROM student ORDER BY mark DESC
OPEN CUR_COUNT
FETCH NEXT FROM CUR_COUNT INTO @NAME
WHILE (@@FETCH_STATUS = 0)
BEGIN
IF (@NAME = 'ME')
BEGIN
SET @ROWCOUNT = @ROWCOUNT + 1
BREAK
END
ELSE
BEGIN
SET @ROWCOUNT = @ROWCOUNT + 1
END
FETCH NEXT FROM CUR_COUNT INTO @NAME
END
CLOSE CUR_COUNT
DEALLOCATE CUR_COUNT
SELECT @ROWCOUNT AS ROW_ORDER
|
|
|
|
|
|
|
|
楼主 |
发表于 22-4-2005 11:14 AM
|
显示全部楼层
谢谢2位提供的思路
goatstudio老大 提供的我大概明白也正在使用了。不过每次create一个store procedure会不会很浪费资源?
因为学生很多。是不是一个store procedure 里面的 IF (@NAME = 'ME')
的'ME'可以用asp更改??
白日梦老大你说的Quick Search routine能有更明白的例子吗?
我很笨,没有例子我很难理解。。不好意思。。 |
|
|
|
|
|
|
|
发表于 22-4-2005 11:27 AM
|
显示全部楼层
CREATE PROCEDURE [SP_OrderCheck]
@STUDENT VARCHAR (10)
AS
DECLARE @NAME VARCHAR (20)
DECLARE @ROWCOUNT INT
SET @ROWCOUNT = 0
DECLARE CUR_COUNT CURSOR
FOR SELECT name FROM student ORDER BY mark DESC
OPEN CUR_COUNT
FETCH NEXT FROM CUR_COUNT INTO @NAME
WHILE (@@FETCH_STATUS = 0)
BEGIN
IF (@NAME = @STUDENT)
BEGIN
SET @ROWCOUNT = @ROWCOUNT + 1
BREAK
END
ELSE
BEGIN
SET @ROWCOUNT = @ROWCOUNT + 1
END
FETCH NEXT FROM CUR_COUNT INTO @NAME
END
CLOSE CUR_COUNT
DEALLOCATE CUR_COUNT
SELECT @ROWCOUNT AS ROW_ORDER
当你要执行时就这样写:
SP_OrderCheck 'me' |
|
|
|
|
|
|
|
楼主 |
发表于 22-4-2005 11:39 AM
|
显示全部楼层
|
|
|
|
|
|
| |
本周最热论坛帖子
|