Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 82b2e1c

Browse files
多属性查询
1 parent e939821 commit 82b2e1c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ where b.skill_level>0 and c.skill_level>0 and d.skill_level>0;
1717

1818
使用一张物理表变成多个逻辑表多次连接的方式解决同一个属性多个值的过滤问题
1919

20-
21-
22-
20+
********************************************************************************
21+
过滤条件有多个,当任意两个满足就ok的SQL查询语句的思路,使用求和的方式来实现。
22+
select a.user_name,b.skill,c.skill,d.skill
23+
from user1 a
24+
join user_skill b on a.id=b.user_id and b.skill='念经'
25+
join user_skill c on c.user_id= b.user_id and c.skill='变化'
26+
join user_skill d on d.user_id = c.user_id and d.skill='腾云'
27+
Where (case when b.skill is not null then 1 else 0 end)
28+
+(case when c.skill is not null then 1 else 0 end)
29+
+(case when d.skill is not null then 1 else 0 end)
30+
+(case when e.skill is not null then 1 else 0 end)>=2;
2331

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /