房天下 > 房天下问答 > 业主生活 > 其他
  • SQL排序问题,高手请指教

    默认是按"xe"字段排序:by xe desc创建一个字段,yxp,一般情况下yxp无数据,当有一数据要排上来的时候才用。例如yxp=5时,它就会排到第5位。而本来按xe排序的次序不变,但要让让yxp=5的插入到第5.我想实现插入排序。但又无从入手,请高手指教并详细说明。

    提问者:联众江湖

    发布于2010-09-22

共1个回答
  • xxyyjjhh 丨Lv 0
    function 函数(s) '判断yxp的排号是否与当序号想对应 set frs=conn.execute("select * from 表 where yxp="&s) if frs.eof then 函数=false else 函数=true end if set frs=nothingend functionsub 过程(s) '输出yxp的数据 set grs=conn.execute("select * from 表 where yxp="&s) if not grs.eof then '输出此yxp的相应数据 end if set grs=nothingend subfor k = 1 to rs.recordcountif 函数(k) then '调用函数判断此序号是否被排号所占 call 过程(k) '输出此排号的相应数据 rs.moveprevious '指针上移一条,避免遗漏数据else for i=k to rs.recordcount if rs.eof then exit for if not isnumeric(rs("yxp")) then 'yxp字段的数据类型是数字 '如果不是数字 输出自然排序的数据 exit for '退出循环 end if rs.movenext nextend ifrs.movenextnext不知道你要的是不是这效果,测试OK cs字段是用来做对比的,直接复制修改字段名就可测试<!--#include file="conn.asp"--><%function functioncode(s) dim srs set crs=conn.execute("select * from news where pxy="&s) if crs.eof then functioncode=false else functioncode=true end if set crs=nothingend functionsub subcode(s) dim srs set srs=conn.execute("select * from news where pxy="&s) if not srs.eof then response.write "<tr><td>"&s&"</td><td>"&srs("cs")&"</td><td>"&srs("title")&"</td></tr>" end if set srs=nothingend subsql = "select * from news order by xe desc" set rs=server.createobject("adodb.recordset") rs.open sql,conn,1,1 if not rs.bof and not rs.eof thenresponse.write "<table border=1 align=center width=500>"for k = 1 to rs.recordcountif functioncode(k) then call subcode(k) rs.movepreviouselse for i=k to rs.recordcount if rs.eof then exit for if not isnumeric(rs("pxy")) then response.write "<tr><td>"&k&"</td><td>"&rs("cs")&"</td><td>"&rs("title")&"</td></tr>" exit for end if rs.movenext nextend ifrs.movenextnextresponse.write "</table>"end ifrs.closeset rs=nothingcall close_conn%>
    +1 2010-09-22 举报
热门人气推荐
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。