Knex.js 获取最大计数
我想使用Knex.js 获取最大计数,knex.js,bookshelf.js,Knex.js,Bookshelf.js,我想使用knex.js bookshelf.knex('user').distinct('social_name') .select('social_image_url') .count('status as score').innerJoin('game', function(){ this.on('game.user_id', 'user.id'); }).innerJoin('round', function(){
knex.js
bookshelf.knex('user').distinct('social_name')
.select('social_image_url')
.count('status as score').innerJoin('game', function(){
this.on('game.user_id', 'user.id');
}).innerJoin('round', function(){
this.on('round.game_id', 'game.id');
}).where('status', 'win')
.groupBy('game.id', 'user.id')
.orderBy('score', 'desc')
.limit(10)
.then(function(top10){
callback(null, top10);
}).catch(function(err){
callback(err);
});
但这就是我得到的
[ { social_name: 'B', social_image_url: '.....', score: 4 },
{ social_name: 'A', social_image_url: '.....', score: 3 },
{ social_name: 'A', social_image_url: '.....', score: 2 } ]
我得到了两个社交名称的记录:A
,而不是只得到它的最大值
{ social_name: 'A', social_image_url: '.....', score: 3 }
我最终解决了这个问题,首先创建子查询,然后使用内部连接