Skip to content

Commit e939821

Browse files
committed
多属性查询
1 parent 957603e commit e939821

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

mysql开发技巧三/多属性查询

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
查询同一字段的不同值,两表关联时要第一张表要join多次第二张表(不同的值有几种就关联几次)
3+
4+
select s1.username,s1.skill,s2.skill from skills s1 join
5+
skills s2 on s1.username=s2.username where s1.skill='变化' and s2.skill='念经' and
6+
s1.skill_level>0 and s2.skill_level>0;
7+
8+
9+
********************************************************************************
10+
解决同属性多值过滤的问题
11+
select a.user_name,b.skill,c.skill,d.skill
12+
from user1 a
13+
join user_skill b on a.id=b.user_id and b.skill='念经'
14+
join user_skill c on c.user_id= b.user_id and c.skill='变化'
15+
join user_skill d on d.user_id = c.user_id and d.skill='腾云'
16+
where b.skill_level>0 and c.skill_level>0 and d.skill_level>0;
17+
18+
使用一张物理表变成多个逻辑表多次连接的方式解决同一个属性多个值的过滤问题
19+
20+
21+
22+
23+

0 commit comments

Comments
 (0)