SQL查询以查找共享完全相同的一组值的对 [英] SQL query for finding pairs that share the exact same set of values
本文介绍了SQL查询以查找共享完全相同的一组值的对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法针对此问题生成查询.
I'm having trouble generating a query for this problem.
我有这个小桌子
Tasks(employee_name, task)
Sample Data:
Tasks
------------------
Joe | taskA
Joe | taskB
Ted | taskA
Jim | taskB
Ray | taskA
Ray | taskB
John| taskA
Tim | taskC
我需要找到任务完全相同的所有员工对.
I need to find all pairs of employees that have the exact same tasks.
例如,使用结果集上方的数据应为:
For example using the data above the result set should be:
---------------------
employee1 | employee2
---------------------
Joe | Ray
Ted | John
我正在使用mySQL作为数据库. 谢谢!
I'm using mySQL for the database. Thanks!
推荐答案
select a.employee_name,b.employee_name
from tasks as a, tasks as b
where a.employee_name>b.employee_name
group by a.employee_name,b.employee_name
having group_concat(distinct a.task order by a.task)=group_concat(distinct b.task order by b.task)
这篇关于SQL查询以查找共享完全相同的一组值的对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文