我有一个表swipe
,我需要迭代它来填充一个数组,我可以使用该数组向用户显示匹配列表
。结构如下(两个用户之间的有效匹配):
这是我的原始逻辑,用于迭代表并获取将插入数组的匹配对象
:
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 查询
或 Node 代码执行此操作?
谢谢!
最佳答案
我对 Node 一无所知,但是你想要运行的 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
关于mysql - 遍历mysql表以填充Node中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56755250/