select name from 
(
  SELECT distinct name FROM tb_KS WHERE km='数学' 
  union all
  SELECT distinct name FROM tb_KS WHERE km='英文' 
) t
group by name having count(*) = 2
--------------------------------------
select * from tb_ks where name in 
(
select name from 
(
  SELECT distinct name FROM tb_KS WHERE km='数学' 
  union all
  SELECT distinct name FROM tb_KS WHERE km='英文' 
) t
group by name having count(*) = 2
)

解决方案 »

  1.   

    select * from tb_ks t where exists(
    select 1 from tb_ks where name=t.name and (km='数学' or km='英文')
    group by name having count(1)>1
    )
      

  2.   

    select * from tb_ks where km ='语文'  and name in(select name from tb_ks where km ='数学')  
      

  3.   

    为啥?
    select * from tb_ks where km ='数学' and name in(select name from tb_ks where km ='英文')  
    只要把对应的语文和数学换成你对应的就可以了阿