更具体地说,对于问题和标签之间的多对多关系作为sql server表(包括帮助表QuestionsWithTags),需要一个query / sp,它返回所有具有以下标记集“t1”的问题,“t2”和“t3”。 鉴别器没有任何标签,但所有这些标签都不少于此。
提前致谢。
答案 0 :(得分:6)
您可以使用聚合和having
子句来解决此问题:
select questionid
from QuestionsWithTags qwt
group by questionid
having count(distinct tag) = 3 and
count(distinct case when tag in ('t1', 't2', 't3') then tag end) = 3;