从数据库中选择随机数据 [英] select random data from database
本文介绍了从数据库中选择随机数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有10个从数据库中检索到的问题.
每当我每次登录时,i都应该收到被打乱的问题.
如果我以1个用户名登录,则会遇到相同的问题;如果我以2个用户名登录,则会遇到相同的问题.
我的要求是应该以随机方式进行.
请帮助我.
I have 10 question which are retrieved from a database.
Whenever I login each and every time iIshould get the shuffled question.
If I login as 1 username I got the same question and if I login as 2 username I got the same question.
My requriment is it should be in shuffled manner.
Please help me.
推荐答案
使用以下查询
use the following query
SELECT TOP 10 * FROM YourTable ORDER By NEWID()
有关更多详细信息,请参见链接 http://haacked.com/archive/2004/06/21/658 .aspx [ ^ ]
for more details please see the link http://haacked.com/archive/2004/06/21/658.aspx[^]
使用RAND()
或NEWID()
使用TABLESAMPLE从SQL Server中检索随机数据 [ ^ ]
随机检索SQL Server记录 [从SQL Server表中选择n个随机行 [ ^ ]
UseRAND()
orNEWID()
Retrieving random data from SQL Server with TABLESAMPLE[^]
Randomly Retrieve SQL Server Records[^]
Select n random rows from SQL Server table[^]
这篇关于从数据库中选择随机数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文