我有一份问题单,每个问题都与一份标书清单有关。
以下数据:
Question1 : Tag1
Question2 : Tag1, Tag2
Question3 : Tag1, Tag2, Tag3
Question4 : Tag1, Tag3
以下标准:
var tagsIds = new int[] { tag1, tag2 };
var res = session.CreateCriteria<Question>()
.CreateCriteria( "Tags" )
.Add( Restrictions.In( "id", tagsIds ) )
.List<Question>();
返回(我理解为什么“in”像OR)一样行事。
Question1, Question2, Question3, Question4
或者,我只想到。
Question2, Question3
as they both have tag1 AND tag2. I there a way to do it ?
在座各位:
SELECT *
FROM Question q
WHERE EXISTS (
SELECT *
FROM QuestionsToTags qtt
WHERE qtt.Question_id = q.Id
AND qtt.Tag_id IN ( 1, 2 )
GROUP BY qtt.Question_id
HAVING COUNT( qtt.Question_id ) >= 2
)