1

我有以下方式的表格:


Class | Dept | programs |        
.........................        
1     | 1    |2001      |     
.........................   
1     | 1    |2002      |     
.........................   
2     | 1    |2001      |     
.........................   
2     | 1    |2003      |     
.........................  
3     | 1    |2003      |     
.........................  
3     | 1    |2004      |     
.........................  

我的问题是,当我选择select distinct programs where class in (1,2)查询时,将返回 2001、2002、2003。我只想选择对 1 和 2 通用的程序,即 2001。同样,当我在 (2,3) 中搜索类时应该只返回 2003。

这可能吗?

4

1 回答 1

1

你可以试试下面

演示

select programs
from tablename t1
where class in (1,2)
group by programs
having count(distinct class) =2
于 2018-11-19T05:16:32.923 回答