实现 通过数据库里一个字段值相等 则把 他合为一条数据
生活随笔
收集整理的這篇文章主要介紹了
实现 通过数据库里一个字段值相等 则把 他合为一条数据
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?
需求: 把紅色合為一條數(shù)據(jù),綠色合為一條數(shù)據(jù)
結(jié)果:?
?
不多說(shuō)直接上代碼.........................................................
// 先查所有數(shù)據(jù) const goods = await service.goods.findAllGoodsWithParams({where: params,offset: ctx.pagination.skip,limit: ctx.pagination.limit,}); // 循環(huán)查出數(shù)據(jù)const map = {};const temp = [];for (let i = 0; i < goods.rows.length; i++) { // shop_id 是所屬店鋪?zhàn)侄蝐onst 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;
轉(zhuǎn)載于:https://www.cnblogs.com/malng/p/10156602.html
總結(jié)
以上是生活随笔為你收集整理的实现 通过数据库里一个字段值相等 则把 他合为一条数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 查看串口的驱动信息
- 下一篇: js parseInt()与Number