Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-07 16:23:03
Original
2680 people have browsed it

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  

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!