Node.js 在knexjs中,如何仅获取一行中的某些列值相同
我试图从表中获取不同的值Node.js 在knexjs中,如何仅获取一行中的某些列值相同,node.js,knexjs,Node.js,Knexjs,我试图从表中获取不同的值 let records = db .select("*") .from("user_technical_skill") .distinct('technical_skill_id') 例如,在user\u technical\u skill表中 [{ "id": "84ed9c04-b1d3-4e69-b2d2-c569ad94545f", "u
let records = db
.select("*")
.from("user_technical_skill")
.distinct('technical_skill_id')
例如,在user\u technical\u skill
表中
[{
"id": "84ed9c04-b1d3-4e69-b2d2-c569ad94545f",
"user_id": "5dfbf2cc-38f9-4388-a077-11480e62d893",
"technical_skill_id": "111",
"created_at": "2021-04-11T15:31:39.552Z",
"updated_at": "2021-04-11T15:31:39.552Z"
},
{
"id": "4b0fcdd6-cbab-4fdf-ada6-0154c7956630",
"user_id": "a3b91e2a-5d7e-4528-b496-3a0807299db7",
"technical_skill_id": "111",
"created_at": "2021-04-11T15:48:49.145Z",
"updated_at": "2021-04-11T15:48:49.145Z"
}]
技术技能id为11的两列
但它不起作用。我再次得到查询中的两列
如何解决此问题?如果需要所有列,可以使用group by而不是distinct()
let records=db
。选择(“*”)
.来源(“用户技术技能”)
.groupBy('technical\u skill\u id')
否则,如果你只需要用户的技术技能,你可以使用
let records=db.from(“用户技术技能”).distinct(“技术技能id”)
您不需要select(“*”),因为distinct类似于select选项
参考:
“name”:“error”,“length”:248,“severity”:“error”,“code”:“42803”,“position”:“8”,“file”:“d:\\pginstaller\u 12.auto\\postgres.windows-x64\\src\\backend\\parser\\parse\u agg.c”,“line”:“1409”,“例程”:“check\u ungroup\u columns\u walker”
执行此操作时出错。。。