我在为这个问题创建查询时遇到了一些问题。
我需要找到哪些人有WorkedOn
Building but have not Financed
together.
我的 table :
Build(person, financed, workedOn)
Person | Financed | WorkedOn
-----------------------------
Person1| Build1 | Build4
Person2| Build2 | Build5
Person3| Build1 | Build5
Person4| Build2 | Build3
Person5| Build3 | Build1
Person6| Build1 | Build5
Person7| Build4 | Build3
Person8| Build5 | Build3
正确的查询应该产生这样的结果:
Person
-------
Person7 Person8
Person8 Person4
Person6 Person3
我试过使用 distinct
和 having
我只是觉得不太对劲。任何帮助将不胜感激,我正在使用 sqlite3,谢谢 :)
最佳答案
SELECT t1.person, t2.person
FROM build t1, build t2
WHERE t1.workedon = t2.workedon
AND t1.financed != t2.financed
AND t1.person > t2.person
关于mysql - 用于查找共享某些值但不共享其他值的对的 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33711064/