zoukankan      html  css  js  c++  java
  • 实现 通过数据库里一个字段值相等 则把 他合为一条数据

    需求: 把红色合为一条数据,绿色合为一条数据

    结果: 

    不多说直接上代码.........................................................

    // 先查所有数据
    const goods = await service.goods.findAllGoodsWithParams({
          where: params,
          offset: ctx.pagination.skip,
          limit: ctx.pagination.limit,
        });
    // 循环查出数据
        const map = {};
        const temp = [];
        for (let i = 0; i < goods.rows.length; i++) {
    // shop_id   是所属店铺字段
          const good = goods.rows[i];
          const key = good.shop_id;
          if (!map[key]) {
            map[key] = good.shop_id;
            temp.push(good);
          }
        }
        ctx.status = 200;
        ctx.body = temp;
    

      

  • 相关阅读:
    感想2
    感想1
    记录4
    记录3
    记录2
    记录1
    库存物资管理系统-测试
    开学测试
    大二下开学测试有感
    大二下周总结一
  • 原文地址:https://www.cnblogs.com/malng/p/10156602.html
Copyright © 2011-2022 走看看