0

I have a table which looks as follows;

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

Now I need a query in Oracle that should give me only those values of Column B which have all values of Column C in common (here 177, 178,179,180). The answer here is obviously UK1 and UK2 but how to get a query for this? Thanks

4

2 回答 2

2

您可以使用类似于以下内容的查询:

select ColumnB
from yt
group by ColumnB
having count(distinct ColumnC) = (select count(distinct ColumnC)
                                  from yt);

请参阅带有演示的 SQL Fiddle

于 2013-04-29T10:47:08.950 回答
-3

请试试:

select ColumnA, ColumnB From YourTable
where ColumnC in (177, 178, 179, 180)
group by ColumnA, ColumnB
having count(distinct ColumnC)=4
于 2013-04-29T10:59:22.377 回答