[英]Get All record when like each other join query
I have one table registration我有一张桌子注册
registration table
+------+------+
|ARIDNR|LIEFNR|
+------+------+
|1 |A |
+------+------+
|2 |B |
+------+------+
|3 |C |
+------+------+
UserLike Table
+------+------+
|ARIDNR|LIEFNR|
+------+------+
|A |B |
+------+------+
|B |A |
+------+------+
|A |C |
+------+------+
I would like to select join query with userlike table get those value return true when both user like each other我想选择带有 userlike 表的连接查询,当两个用户彼此喜欢时,这些值返回 true
Example例子
User A is like User B Also User B is Like User A用户 A 和用户 B 一样 用户 B 也像用户 A
so I get return true in User B response所以我在用户 B 的响应中得到 return true
in this case User A is like User C but User C is not Like User A in this case return false在这种情况下用户 A 就像用户 C 但用户 C 不像用户 A 在这种情况下返回 false
I want output like below我想要像下面这样的输出
Result结果
{
“username”:B
“match”:true
},
{
“username”:C
“match”:false
}
Assuming now duplicates, you can do:假设现在重复,您可以执行以下操作:
select least(ARIDNR, LIEFNR), greatest(ARIDNR, LIEFNR)
from userlike
group by least(ARIDNR, LIEFNR), greatest(ARIDNR, LIEFNR)
having count(*) = 2;
Or, more efficiently (with the right indexes) as:或者,更有效地(使用正确的索引)如下:
select ul.*
from userlike ul
where ul.ARIDNR < ul.LIEFNR and
exists (select 1
from userlike ul2
where ul2.ARIDNR = ul.LIEFNR and
ul2.LIEFNR = ul.ARIDNR
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.