幽灵资源网 Design By www.bzswh.com

SQL Server:
复制代码 代码如下:
Select TOP N * From TABLE Order By NewID()  
view plaincopy to clipboardprint?
Select TOP N * From TABLE Order By NewID()

Select TOP N * From TABLE Order By NewID()

NewID()函数将创建一个 uniqueidentifier 类型的唯一值。上面的语句实现效果是从Table中随机读取N条记录。

Access:
复制代码 代码如下:
Select TOP N * From TABLE Order By Rnd(ID)   
view plaincopy to clipboardprint?
Select TOP N * From TABLE Order By Rnd(ID) 

Select TOP N * From TABLE Order By Rnd(ID)

Rnd(ID) 其中的ID是自动编号字段,可以利用其他任何数值来完成,比如用姓名字段(UserName)
复制代码 代码如下:
Select TOP N * From TABLE Order BY Rnd(Len(UserName))  
view plaincopy to clipboardprint?
Select TOP N * From TABLE Order BY Rnd(Len(UserName))

Select TOP N * From TABLE Order BY Rnd(Len(UserName))

MySql:
复制代码 代码如下:
Select * From TABLE Order By Rand() Limit 10  
view plaincopy to clipboardprint?
Select * From TABLE Order By Rand() Limit 10

Select * From TABLE Order By Rand() Limit 10

postgreSQL:
复制代码 代码如下:
select * from glxt022 order by random() limit 5  
view plaincopy to clipboardprint?
select * from glxt022 order by random() limit 5

标签:
数据库,随机查询

幽灵资源网 Design By www.bzswh.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
幽灵资源网 Design By www.bzswh.com