我们如何从数据库中随机选择5行 [英] how can we pick 5 rowsradomly from database

查看:103
本文介绍了我们如何从数据库中随机选择5行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有reiremetid,我的数据库中有问题,我们如何根据需求ID从数据库中随机选择5个问题


i have reiremetid, questions in my database ,how we pick 5 questions randomly from database based on requirement id

推荐答案

我可以给你一个想法.
首先,您需要在数据库的需求ID值内从您的代码中随机生成5个需求ID(如果它们是序列号,那会很好).
其次,您可以根据自己的需求轻松选择相应的5个问题.
对于您来说,创建5个随机id的最重要部分以及第一个之后的其他部分应该足够容易.
I can give you one idea.
First,you need to randomly generate 5 requirement id from your code within your requirement id values of your database(it would be good if they are serial numbers).
Second,then you can easily select corresponding 5 questions according to their reiremetid.
The most important part here for you to create 5 random id and other part should be easier enough after first one.


对于sql server来说,就是这样:
For sql server this is it:
SELECT TOP 5 column FROM table
ORDER BY NEWID()



对于其他数据库,请查看以下内容:
http://www.petefreitag.com/item/466.cfm [



For other databases have a look at this :
http://www.petefreitag.com/item/466.cfm[^]


这篇关于我们如何从数据库中随机选择5行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆