从另一列中的每个唯一值从列中随机选择一个值

发布于 2025-02-12 19:14:07 字数 692 浏览 0 评论 0原文

我一直在完成似乎很简单的任务。但是,我整天都在没有进步的情况下度过了一整天,我相信现在是时候向这个社区寻求帮助了。我只有2列的下表:

钥匙编号
角色11111
角色22222
角色33333
Personb44444
Personb55555

我需要随机选择与某人关联的密钥编号并将其显示在新表中。我需要与随机键号一起显示所有人员。与人相关的密钥数量为2-5。下面显示了输出表的一个示例:

钥匙编号
Persona22222
Personb44444

关于如何处理此任务的任何想法?

提前致谢!

I've been working on a task that seems pretty straightforward. However, I've spent this entire day without progressing and I believe it's now time to ask this community for help. I have the following table with simply 2 columns:

Personkey numbers
PersonA11111
PersonA22222
PersonA33333
PersonB44444
PersonB55555

I need to randomly select a key number associated with a person and display it in a new table. I need to display all persons alongside a random key number. The number of keys associated with a person ranges from 2-5. An example of the output table is displayed below:

Personkey numbers
PersonA22222
PersonB44444

Any ideas on how to approach this task?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

霓裳挽歌倾城醉 2025-02-19 19:14:07

尝试此代码:

选择不同的人,first_value([键号]),而不是(从表格订购(按newid()划分)从表划分

Try This Code :

SELECT DISTINCT Person ,FIRST_VALUE([key numbers]) OVER (PARTITION BY Person ORDER BY NEWID()) FROM TABLE

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文