SELECT WHERE Subitem仅包括 [英] SELECT WHERE Subitem ONLY include

查看:81
本文介绍了SELECT WHERE Subitem仅包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表,有两列,A列和B列



A,B

1,1

1,2

1,3

1,4

1,5


2,1

2,2

2,3



3,2

3,6 $ / b
3,4



4,1

4,2

4,3



现在我只想要列A的值,其中列B必须具有值1,2和3

因此结果将是 2和4



我只是不能今天记得我的SQL ...任何帮助??



SELECT DISTINCT(A)FROM my_Table WHERE ??????

I have a simple table with two columns, Column A and B

A, B
1, 1
1, 2
1, 3
1, 4
1, 5

2, 1
2, 2
2, 3

3, 2
3, 6
3, 4

4, 1
4, 2
4, 3

Now I only want Values of Column A where Column B MUST have the values of 1,2 and 3
So the result would be 2 and 4.

I simply cant remember my SQL today... any help ??

SELECT DISTINCT(A) FROM my_Table WHERE ??????

推荐答案

可能不是最好的方法,但它的工作原理和确实有效,它适用于任何版本的SQL

Probably not the nicest way to do this but it works and does have the advantage that it will work for any version of SQL
select DISTINCT (A) from my_Table
where A in (select A from my_Table where B = 1)
and A in (select A from my_Table where B = 2)
and A in (select A from my_Table where B = 3)
and A not in (select A from my_Table where B not in (1,2,3))





这篇关于SELECT WHERE Subitem仅包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆