2 Star 0 Fork 0

wscaco3 / mysql_tech

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
duo_zhi_guo_lv.md 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
wscaco3 提交于 2015-11-19 14:43 . Update duo_zhi_guo_lv.md

同属性多值过滤

如何查询出同时具有变化念经这两项技能的取经人?

select a.user_name,b.skill,c.skill from user1 a 
join user1_skills b on a.id = b.user_id and b.skill = '念经'
join user1_skills c on c.user_id = b.user_id and c.skill = '变化'
where b.skill_level > 0 and c.skill_level >0;

如何查询出具有变化念经腾云浮水其中两项技能的取经人?

select a.user_name,b.skill,c.skill,d.skill,e.skill
from user1 a 
left join user1_skills b on a.id = b.user_id and b.skill ='念经' and b.skill_level > 0
left join user1_skills c on a.id = c.user_id and c.skill ='变化' and c.skill_level > 0
left join user1_skills d on a.id = d.user_id and d.skill ='腾云' and d.skill_level > 0
left join user1_skills e on a.id = e.user_id and e.skill ='浮水' and e.skill_level > 0
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;

使用group方法

select a.user_name from user1 a 
join user1_skills b on a.id = b.user_id
where b.skill in ('念经','变化','腾云','浮水') and b.skill_level >0 
group by a.user_name having count(*) >=2;
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wscaco3/mysql_tech.git
git@gitee.com:wscaco3/mysql_tech.git
wscaco3
mysql_tech
mysql_tech
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891