如何在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