1 access数据库:Select Top 100 * From 表 where xx>10 order By Rnd(ID)
2 mysql数据库:Select Top 100 * From 表 where xx>10 order By NewID()
3 sql server:Select * From 表 o where xx>10 order By Rand() Limit 10
[Quote=引用 3 楼 myvicy 的回复:]
Function RndID()
Dim rs As New ADODB.Recordset
Dim strsql As String
strsql = "select * from 1"
rs.CursorLocation = adUseClient
rs.Open strsql, CurrentProject.Connection, 2, 3
’在Access中可以使用 CurrentProject.Connection,
’其他语言中可以用 ADODB.CONNECTION对象。
Dim i As Long
Dim lngCount As Long
Dim lngRnd As Long
lngCount = rs.RecordCount
’一下取前10条随机记录
For i = 1 To 1…
[/Quote]恩。。应该这个可行。有没更高效率的方法?
[Quote=引用 1 楼 myvicy 的回复:]
1 access数据库:Select Top 10 * From 表 order By Rnd(ID)
2 mysql数据库:Select Top 10 * From 表 order By NewID()
3 sql server:Select * From 表 order By Rand() Limit 10
[/Quote]你这个仅仅是随机无条件地选取10条记录。我的意思是说,在我的SQL基础上,select top 100 * from test where xx>10 order by xx desc.再进行随机显示
Function RndID()
Dim rs As New ADODB.Recordset
Dim strsql As String
strsql = "select * from 1"
rs.CursorLocation = adUseClient
rs.Open strsql, CurrentProject.Connection, 2, 3
’在Access中可以使用 CurrentProject.Connection,
’其他语言中可以用 ADODB.CONNECTION对象。
Dim i As Long
Dim lngCount As Long
Dim lngRnd As Long
lngCount = rs.RecordCount
’一下取前10条随机记录
For i = 1 To 10
lngRnd = Int((lngCount * Rnd) + 1)
rs.AbsolutePosition = lngRnd
Debug.Print rs("id")
Next
End Function
参考:http://www.aspxhome.com/asp/aspskills/20079/153111.htm
1 access数据库:Select Top 10 * From 表 order By Rnd(ID)
2 mysql数据库:Select Top 10 * From 表 order By NewID()
3 sql server:Select * From 表 order By Rand() Limit 10