如何在sql server中选择仅与IN列表匹配的项目 [英] How to select item matching Only IN List in sql server
本文介绍了如何在sql server中选择仅与IN列表匹配的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在IN列表中只选择他想要的项目?例如
How can one select only the items he want in the IN list? for example
select * from pagetags where TagID in (1,2,4)
现在我想要所有分配了上述 3 个 ID 的所有页面 (1,2,4),不是其中的任何一个而是所有的?
Now I want all the pages which has all the above 3 IDs assigned to them (1,2,4), not just any of them but all of them?
有办法吗?还有其他运营商吗?我已经尝试过 = Any
和 = All
但没有运气.
Is there a way? any other operator? I have already tried = Any
and = All
but no luck.
推荐答案
这类问题的术语是 关系划分.下面的一种方式.
The term for this type of problem is relational division. One way below.
SELECT PageID
FROM pagetags
WHERE TagID IN ( 1, 2, 4 )
GROUP BY PageID
HAVING Count(DISTINCT TagID) = 3
这篇关于如何在sql server中选择仅与IN列表匹配的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文