我有这张表 (Prefrences_Table)
--------------------------
|student | Preferences |
--------------------------
Stud A | Stud B
Stud A | Stud C
Stud B | Stud E
Stud B | Stud A
Stud C | Stud F
Stud F | Stud B
--------------------------
如果“Stud A”在他的偏好列表中添加了“Stud B”,我想检查“stud B”是否也在他的偏好列表中添加了“stud A”,所以我可以将他们都添加到一个组中. 如何使用 SQL 或 C# 完成此操作?
最佳答案
自连接在这里应该工作得很好。附加谓词仅返回匹配项的第一个实例以避免重复。
select t.student, t1.student
from
Prefrences_Table t
inner join Prefrences_Table t1
on t.student = t1.preferences
and t.preferences = t1.student
and t.student < t1.student
关于c# - 检查并比较 sql server 表中的列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19185363/