我刚学的delphi,在做一个系统,有一步需要从一个表的200行里随机选取100行,请问这个怎么写

解决方案 »

  1.   

    1)使用random随机产生行号,注意避免重复
    2)使用random随机起点后,然后等距离取
    3)使用random产生若干可互换位置的行号,最后取100个
      

  2.   

    语句中的table表示表名,str表示字符型文本。
    统计数据:sql="select count(*) as id from table",调用:<%=rs("id")%>
    精确查询:sql="select * from table where auther="&str&"order by id desc"
    模糊查询:sql="select * from table where title like %"&str&"%order by id desc"
    随机查询:Randomize
    rid=int(rnd*20+1)
    Set test_ti=Conn.Execute("SELECT * from table where id="&rid)
    从表中取出第N条到第M条记录:SELECT TOP m-n+1 * FROM table WHERE (id NOT IN (SELECT TOP n-1 id FROM table))
    不过用in的效率不好,不如用这个:select * from tableName where id > (select top 1 id from tablename order by id asc)
    随机取出n条记录:Sql server:select top n * from 表 order by newid()
    Access:SELECT top n * FROM 表 ORDER BY Rnd(id) 
    mysql:Select * From 表 Order By rand() Limit n