实现 通过数据库里一个字段值相等 则把 他合为一条数据
生活随笔
收集整理的這篇文章主要介紹了
实现 通过数据库里一个字段值相等 则把 他合为一条数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
需求: 把紅色合為一條數據,綠色合為一條數據
結果:?
?
不多說直接上代碼.........................................................
// 先查所有數據 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;
轉載于:https://www.cnblogs.com/malng/p/10156602.html
總結
以上是生活随笔為你收集整理的实现 通过数据库里一个字段值相等 则把 他合为一条数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 查看串口的驱动信息
- 下一篇: MS SQL 分页存储过程