mysql - 遍历mysql表以填充Node中的数组

标签 mysql sql node.js

我有一个表swipe,我需要迭代它来填充一个数组,我可以使用该数组向用户显示匹配列表。结构如下(两个用户之间的有效匹配):

enter image description here

这是我的原始逻辑,用于迭代表并获取将插入数组的匹配对象:

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/

相关文章:

MySQL (MariaDB) float 可视化 : why are values rounded to hundreds or thousands?

javascript - JSON.stringify 自定义格式

mysql - 如何过滤日期和时间

php - 在MySQL插入之前使用redis作为中介

php - 如何选择在过去 2 小时内或根本没有使用 Mysql 更新分数的用户

MySQL:在数据库中制作paypal支付信用系统需要哪些字段?

mysql - 如何在使用动态生成字段的 Sql Server 中添加?

node.js - 在 Node.js 中使用 REST API 时请求参数

node.js - 此 Node 实例的 N-API 版本为 1。此模块支持 N-API 版本 3。此 Node 实例无法运行此模块

phpMyAdmin - mySQL - 将数据导入 WordPress 时出错 - 什么是排序规则?