语句中的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
2)使用random随机起点后,然后等距离取
3)使用random产生若干可互换位置的行号,最后取100个
统计数据: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