在表中查找满足子集频率条件的项目?

发布于 2024-12-22 20:05:26 字数 292 浏览 1 评论 0原文

我有一个非常简单的项目所有权表,包含这两列:

UserID, ItemID

UserID 有索引,但 ItemID 没有索引。

我有一组 S,由 10-40 个特定的 ItemID 组成(在我的查询中,它们只是逗号分隔的整数列表)。

我想找到 S 中至少拥有 X 个(不同的 ItemID)项的所有 UserID

如果重要的话,我正在使用 MSSQL。这可以有效地完成吗?

I have a very simple item ownership table with these two columns:

UserID, ItemID

There is an index on UserID, but not ItemID.

I have a set S of 10-40 specific ItemIDs (in my queries they are just a comma delimited list of integers).

I want to find all UserIDs that own at least X (distinct ItemIDs) of the items in S.

I am using MSSQL if it matters. Can this be done efficiently?

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

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

发布评论

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

评论(1

多孤肩上扛 2024-12-29 20:05:26
select UserID
from Ownership 
where ItemID in (1,2,3,4,5,...) --your list of ItemIDs
group by UserID
having count(distinct ItemID) >= 3 --the minimum # of distinct items required
select UserID
from Ownership 
where ItemID in (1,2,3,4,5,...) --your list of ItemIDs
group by UserID
having count(distinct ItemID) >= 3 --the minimum # of distinct items required
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文