作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为了简单起见,我们假设该产品是一个工作板 - 使用工作板的人可以通过多个过滤器来过滤工作,例如位置、功能、技能、关键词等
我正在尝试创建一个查询,从表中选择与用户过滤条件匹配的唯一作业。
问题似乎在于将多个 OR 运算符与多个 AND 运算符组合在一起。我想也许表格设置不正确。
使用下表作为一个非常简单的示例,我想查看具有
的职位Location = London OR Manchester
AND
Function = Marketing OR Sales
AND
Keyword = SEO
Note: Location, Function and Keyword are not Groups, they are the
filter of the user searching the jobs (maybe that is the problem?)
JobId | Group | Value
1 | LocationJob | London
1 | LocationCovered | Leeds
1 | FunctionJob | Tech
1 | FunctionJob2 | Engineering
1 | SkillRequired | PHP
1 | SkillOptional | Python
2 | LocationJob | Newcastle
2 | LocationCovered | Manchester
2 | FunctionJob | SEO
2 | FunctionJob2 | PPC
2 | SkillRequired | Marketing
3 | LocationJob | Manchester
3 | LocationCovered | Leeds
3 | FunctionJob | Sales
3 | FunctionJob2 | Business Development
3 | SkillRequired | SEO
结果应为作业 2 和 3
我目前正在执行以下操作,但我有数十万条记录,因此如果有大量连接,速度可能会非常慢..
SELECT TKeywords.UserID
FROM `Search` TKeywords
JOIN `Search` TFunctions ON TKeywords.UserID = TFunctions.UserID AND
TFunctions.Value IN ('Function1', 'Function2','Function3')
JOIN `Search` TSkills ON TKeywords.UserID = TSkills.UserID AND
TSkills.Value IN ('Skills1', 'Skills2','Skills3')
JOIN `Search` TLocation ON TKeywords.UserID = TLocation.UserID AND
TLocation.Value IN ('Location1', 'Location2','Location3')
WHERE TKeywords.Value IN ('Keyword1', 'Keyword2', 'Keyword3')
非常感谢任何帮助。谢谢
最佳答案
这应该有效:
select s1.UserId from search s1
join (
select UserId from search
where Group = 'Industry' and Value = 'Construction'
) s2 on s1.UserId = s2.UserId
where Group = 'Skill' and Value in('PHP', 'Python')
关于mysql - 在 1 列中选择具有多个 AND/OR/IN 条件的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48932121/
我是一名优秀的程序员,十分优秀!