各种数据库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 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
此文章资料整理于:SQL随机查询
本博文章基本上属于原创或收集整理,都是心血结晶。
欢迎转载分享,转载请注明出处,谢谢!
本文地址:各种数据库SQL语句的随机查询
2 条评论
不错,很好很强大,学习了!!!
由 cyheng 于 2011-11-16 17:20:14 最后编辑
最近打算做一个 人事薪资考勤的东西 要开始恶补 sql server了