在SQL中选择不同的对

问题描述 投票:0回答:1

Given table

对于此表,每一列都有不同的行,即count(Name)= count(Spouse_Name)= count(*)想要编写一个SQL查询,其中对(名称和Spouse_Name)是不同的,即Alex Sandra和Sandra Alex相同。

输出应为以下内容:

Output must be this

注意:如果可能,请使用内部联接。

sql inner-join rdbms self-join
1个回答
0
投票

假设namespouse_name在同一行中永远不会相等,您可以像这样使用NOT EXISTS

© www.soinside.com 2019 - 2024. All rights reserved.