在两列中查找共同值

时间:2021-03-14 12:47:31

I have a problem with a query where i need to get all the common values in column #2 that are for every element of column #1.

我有一个查询问题,我需要获得列#2中的所有常见值,这些值是列#1的每个元素。

For example:

Column #1 Column #2
-------------------
21          2.00
21          5.00
21          6.00
21          8.00
21          9.00

41          2.00
41          3.00
41          4.00
41          5.00
41          6.00
41          9.00

52          2.00
52          5.00
52          9.00
52         10.00
52         20.00

Result
-------------------
2.00
5.00

Any help will be greatly appreciated.

任何帮助将不胜感激。

Juan Alvarez

1 个解决方案

#1


3  

SELECT column2
    FROM YourTable
    GROUP BY column2
    HAVING COUNT(*) = (SELECT COUNT(DISTINCT column1) FROM YourTable)

#1


3  

SELECT column2
    FROM YourTable
    GROUP BY column2
    HAVING COUNT(*) = (SELECT COUNT(DISTINCT column1) FROM YourTable)