当前位置:首页 > PHP教程 > PHP总结归纳

使用SQL语句取随机数的方法

sql随机查询语句,[数据库使用技巧]sql语句生成随机数,如何随机显示sql查询语句查询的数据记录集中的20条,随机取出若干条记录的sql语句,使用sql语句取随机数的方法 方法如下: sql server: select top n * from table order by newid() access: dim r r

  sql随机查询语句,[数据库使用技巧]sql语句生成随机数,,如何随机显示sql查询语句查询的数据记录集中的20条,随机取出若干条记录的sql语句,使用sql语句取随机数的方法

方法如下:

sql server:
select top n * from table order by newid()

access:
dim r
randomize
r = rnd
sql = "select top 10 * from table order by rnd(" & r & "-id)"
rnd(" & r & "-id) 其中的id是自动编号字段,可以利用其他任何数值来完成,比如用姓名字段(username)
select top 10 * from table order by rnd(" & r & "-len(username))

mysql:
select * from table order by rand() limit 10

oracle:
select *from (select *from t order by dbms_random.value) where rownum<10

.syntaxhighlighter{padding-top:20px;padding-bottom:20px;}
【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!