在SQL Server中选择具有一组值的行(在连接[和]中的多行中)(select rows with a set of values (in multiple rows in Conjunction [And]) in sql Server)
假设我有一张桌子,如下所示:
id............value ``````````````````` A............1 A............2 A............3 B............1等等。
所以,如果我想选择值为1或2或3的行,我这样做:
select id From table where value in (1,2,3)但是,我想要做的是,选择id与AND而不是OR。 我想要它
所以如果我想选择Id值为1,2和3的行(在这种情况下,结果= A),我该如何选择?
谢谢! (我试图自己做,没有运气,我试图在谷歌搜索,我意识到我的力量甚至知道如何说出问题!所以如果这里的问题不符合我的实际疑问,请随时更改它)
Suppose I have a table like:
id............value ``````````````````` A............1 A............2 A............3 B............1and so on.
so, If I want to select rows with Value either 1 OR 2 OR 3, I do this:
select id From table where value in (1,2,3)But, what I want to do is, select id with AND instead of OR. I want it like
so If I want to select rows where Id has value 1, 2 AND 3, (in this case, resultant = A), how do I select that?
Thanks! (I tried to do it myself, no luck, I tried to search on google, I realized I dint even know how to phrase the question! so if the question here doesnt agree with my actual doubt, feel free to change it)
最满意答案
select id from MyTable where value in (1, 2, 3) group by id having count(distinct value) = 3 select id from MyTable where value in (1, 2, 3) group by id having count(distinct value) = 3更多推荐
发布评论