0
我想用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 } ]
我的social_name: A
兩條記錄,而不是得到它只有最大它是
{ social_name: 'A', social_image_url: '.....', score: 3 }