SQL 查询,如果另一列等于 x,则获取一列 [英] SQL Query, get a columns if another columns equal to x
本文介绍了SQL 查询,如果另一列等于 x,则获取一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一张像这样的桌子
Lets say I have a table that is like this
x y
10 5
10 8
10 12
11 9
11 14
11 12
14 12
14 5
14 11
如果 y = 5,我需要返回所有具有相同值的 x 组所以我需要一个查询来返回值为 10 或 14 的 x 组.查询:
I need to return all the x group that has the same value if y = 5 So I would need a query that would return me the x group that has the value 10 or 14. Query:
select x, y from table ...
应该给我这样的东西:
x y
10 5
10 8
10 12
14 12
14 5
14 11
推荐答案
select x, y
from your_table
where x in
(
select distinct x
from your_table
where y = 5
)
这篇关于SQL 查询,如果另一列等于 x,则获取一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文