Select a.user_name,b.skill,c.skill,e.skill From user1 a From user1 a Left join user1_skill b on a.id =b.user_id and b.skill='念经' and b.skill level>0 Left join user1_skill c on a.id = c.user_id and c.skill='变化' and c.skill_level>0 Left join user1_skill d on a.id = d.user_id and d.skill = '腾云' and c.skill_level>0 Left join user1_skill e on a.id = e.user_id and e.skill = '浮水' and e.skill_level>0 ;
use test
Where (case when b.skill is not null then 1 else 0 end) +(case when c.skill is not null then 1 else 0 end) +(case when d.skill is not null then 1 else 0 end) +(case when e.skill is not null then 1 else 0 end)>=2;