日期:2014-05-18  浏览次数:20584 次

某一列满足两个条件怎么查?
表结构如下:
name col
a 1
a 2
a 2
b 3
b 4
c 1
d 2

如果传入的值为:1,2
那么分组查询满足1,2在col的数据
只有a满足
怎么查询?

------解决方案--------------------
or:

SELECT name
from tb a
where col =1
and exists (
select 1 from tb
where name = a.name
and col = 2
)

or:

SELECT distinct a.name
from tb a,tb b
where a.col =1
and b.name = a.name
and b.col = 2