zoukankan      html  css  js  c++  java
  • 几种取数据库随机记录的方法

    SQL SERVER:
    select top 2 * from pt_login order by newid()
    MY SQL:
    select * from tablename order by rand() limit 10
    ORACLE:
    select *from (select *from t order by dbms_random.value) where rownum<10;
    ACCESS:
    yourstr
    ="*1*3*4*6*12*."
    sql
    ="select top 10 * form yourdb where instr('*'&id&'*','"&yourstr&"')<>0

    <%
       n
    =10    ''取任意10条记录
       set rs = server.CreateObject ("adodb.recordset")
          sql 
    = "select * from table"
          rs.open sql,conn,
    1,1
          count
    =rs.recordcount   ''记录总数
          IF Count<>empty Then
             
    Randomize       
            
    for i = 1 to n       ''循环n次
               num=Fix(Rnd*count) ''num便是随机产生的记录行数,用Fix(),使其不会大于count值。
               rs.move num    ''移到改随机行
               Response.write rs(0)   ''出该条记录
            rs.movefirst     ''别忘了再把指针移到第一条
            next
          
    End IF
          rs.close
       
    set rs = nothing
    %>

  • 相关阅读:
    P3619 魔法
    【HAOI2014】遥感监测
    cdcq的独立博客上线辣!-> http://cdcq.coding.me/blog/
    重复型图床
    【BZOJ1213】高精度开根
    前后端技术
    【HAOI2011】problem b
    【HAOI2011】problem a
    【BZOJ4553】【TJOI2016】【HEOI2016】序列
    【HAOI2015】 T1
  • 原文地址:https://www.cnblogs.com/always/p/500316.html
Copyright © 2011-2022 走看看