MySQL学习教程:使用SQL语句取随机数
作者:[网上资料 ]
在实际工作中我们经常使用到SQL随机查询语句,SQL语句生成随机数,如何随机显示sql查询语句查询的数据记录集中的20条,随机取出若干条记录的SQL语句,如何使用SQL语句取随机数
方法如下:
SQL Server:Select TOP N * From TABLE order By NewID()
Access:dim rrandomizer = rndsql = "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
|
方法如下:
SQL Server:Select TOP N * From TABLE order By NewID()
Access:dim rrandomizer = rndsql = "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
|