秋天是收获的季节。柿子树上缀满了小红灯笼似的柿子,沉甸甸的,把枝头都压弯了。枫树的叶子火红火红的,像一堆正在燃烧的火焰。那梧桐树的枯叶在秋风中纷纷飘落下来,像翩翩起舞的金色蝴蝶。
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 10Select * 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
本文orderbynewid()各种数据库随机查询的方法到此结束。生活总是要改变的,抱守残缺,敝帚自珍终究要被历史所淘汰,要被时代所抛弃;勇于进取,敢于大胆地除旧布新,适时而动虽会经历一时之痛,但新的生命终会在烈火中得到永生。小编再次感谢大家对我们的支持!