我有一个表swipe
,需要对其进行迭代以填充一个数组,该数组可用于向用户显示matches list
。结构如下(两个用户之间的有效匹配):
这是我遍历表并获得match objects
并将其推入数组的原始逻辑:
user = current_user_id;
for (swipes in swipe)
{
if (id_user === user)
{
to_match === id_user_matched;
for (swipes in swipe)
{
if (id_user === to_match && id_user_matched === user)
{
matches_list[].push({“id_match”: id_match, “id_user_matched”: to_match});
}
}
}
}
如何在后端使用sql query
或Node代码来完成此操作?
谢谢!
答案 0 :(得分:1)
我对节点一无所知,但是要运行的SQL看起来像这样:
select s2.id_match, s1.id_user_matched
from swipe s1
inner join swipe s2 ON s2.id_user = s1.id_user_matched and s2.id_user_matched = @user
where s1.id_user = @user