我有一张表格,如下所示;
Column A Column B Column C
--------- --------- --------
GBR UK1 177
GBR UK2 177
GBR UK2 178
GBR UK3 178
GBR UK1 178
GBR UK4 177
GBR UK5 179
GBR UK6 180
GBR UK2 179
GBR UK1 179
GBR UK2 180
GBR UK1 180
现在我在Oracle中需要一个查询,它只能给我B列的值,这些值的C列的所有值都是相同的(这里是177,178,179,180)。答案显然是UK1和UK2但是如何获得查询呢?感谢
答案 0 :(得分:2)
您可以使用类似于以下内容的查询:
select ColumnB
from yt
group by ColumnB
having count(distinct ColumnC) = (select count(distinct ColumnC)
from yt);
答案 1 :(得分:-3)
请尝试:
select ColumnA, ColumnB From YourTable
where ColumnC in (177, 178, 179, 180)
group by ColumnA, ColumnB
having count(distinct ColumnC)=4