mysql:select * from tablename order by rand limit 10
sqlserver:select top 10 * from tablename order by NEWID
ORACLE:使用dbmsrandomvalue种思路方法
SQL>select*from(select*fromtorderbydbms_random.value)whererownum<10;
A
----------
39
101
134
5
83
97
96
140
81
已选择9行
SQL>select*from(select*fromtorderbydbms_random.value)whererownum<10;
A
----------
27
118
141
103
128
10
142
68
74
有人说这是种效率最差思路方法,恳请告知比这更好解决方案!
ACCESS():
yourstr="*1*3*4*6*12*...."
sql="select top 10 * form yourdb where instr(\'*\'&id&\'*\',\'"&yourstr&"\')<>0
ACCESS( 2):
<%
n=10\'\'取任意10条记录
rs = server.CreateObject ("adodb.record")
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
rs = nothing
%>
SQL>select*from(select*fromtorderbydbms_random.value)whererownum<10;
A
----------
39
101
134
5
83
97
96
140
81
已选择9行
SQL>select*from(select*fromtorderbydbms_random.value)whererownum<10;
A
----------
27
118
141
103
128
10
142
68
74
有人说这是种效率最差思路方法,恳请告知比这更好解决方案!
ACCESS():
yourstr="*1*3*4*6*12*...."
sql="select top 10 * form yourdb where instr(\'*\'&id&\'*\',\'"&yourstr&"\')<>0
ACCESS( 2):
<%
n=10\'\'取任意10条记录
rs = server.CreateObject ("adodb.record")
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
rs = nothing
%>
最新评论