sql随机读取N条记录

来源:互联网 发布:嵌入式开发和java 编辑:程序博客网 时间:2024/04/28 23:40

随机取出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

 

select * from youtab where mod ( rowid , 3 ) = 0    

 

建议把MSSQL的联机丛书中的 Transact-SQL 参考大致看一遍,很多东西就心中有数了

mysql中随机提取数据库记录
--------------------------------------------------------------------------------

  1. select * from tablename order by rand() limit 10  

sqlserver中随机提取数据库记录
--------------------------------------------------------------------------------

  1. select top 10 * from tablename order by NEWID()  

Access中随机提取数据库记录
--------------------------------------------------------------------------------

  1. SELECT top 10 * FROM tablename ORDER BY Rnd(FId)  

FId:为你当前表的ID字段名

原创粉丝点击