如何创建一个随机函数,它将随机地从表中记录一行 [英] How can create a random function which will randomly pic a row from table

查看:77
本文介绍了如何创建一个随机函数,它将随机地从表中记录一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在存储过程中创建一个函数.如果我有一个表,其中有多个具有相似名称但不同类别的行,现在我想在该onr行将自动选择之后创建一个随机函数.

Hi, I want create a function in stored procedure. If i have a table in which there are more than one rows which have similar name but different categories, now i want create a random function after that onr row will select automatically.

推荐答案

试试看,

Hi try this,

Select * from tablename order by newid()


这将随机检索行...


this will retrieve the rows randomnly...


要选择随机记录,请结合TOP和NEWID:
To select a random record, combine TOP with NEWID:
SELECT TOP 1 * from MyTable ORDER BY NEWID()

您可能需要用过程输出替换MyTable.

In your case, you will probably need to replace MyTable with your procedure output.


这篇关于如何创建一个随机函数,它将随机地从表中记录一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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