根据sql记录总数如何排序最优化
1.取得记录总数,
2.如果记录总数<5,那么按照ID顺排,如果总数>5,则按照时间排我现在的做是这样,但是有没有更优化的方法
Sql="select count(*) as a from [dati1] where stype=0"
set rs=conn.execute(sql)
totale=rs("a")set rs=server.createobject("adodb.recordset")if int(totale)>5 then
Sql="select top 1 * from [dati] where stype=0 order by datediff(s,getdate(),cstime) asc"
ELSE
Sql="select top 1 * from [dati] where stype=0 order by id asc"
end if Rs.Open Sql,Conn,1,3
if rs.bof and rs.eof then
rs.close
response.write "no-no---"
else
filename=rs("filename")
rs("cktime")=now()
response.write filename & "-" & totale
rs.update
rs.close
end if这样是进行了两次数据库的查询·有没有可以一次到位的!
1.取得记录总数,
2.如果记录总数<5,那么按照ID顺排,如果总数>5,则按照时间排我现在的做是这样,但是有没有更优化的方法
Sql="select count(*) as a from [dati1] where stype=0"
set rs=conn.execute(sql)
totale=rs("a")set rs=server.createobject("adodb.recordset")if int(totale)>5 then
Sql="select top 1 * from [dati] where stype=0 order by datediff(s,getdate(),cstime) asc"
ELSE
Sql="select top 1 * from [dati] where stype=0 order by id asc"
end if Rs.Open Sql,Conn,1,3
if rs.bof and rs.eof then
rs.close
response.write "no-no---"
else
filename=rs("filename")
rs("cktime")=now()
response.write filename & "-" & totale
rs.update
rs.close
end if这样是进行了两次数据库的查询·有没有可以一次到位的!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货