当前位置:   article > 正文

SQL随机查询_随机查询sql

随机查询sql

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 1

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/997146
推荐阅读
相关标签
  

闽ICP备14008679号