2017-03-06 7 views
0

ich eine max Zählung von Datenbank mit knex.jserhalten max Zählung deutliche

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); 
     }); 

bekommen wollen, aber das ist, was ich

[ { social_name: 'B', social_image_url: '.....', score: 4 }, 
    { social_name: 'A', social_image_url: '.....', score: 3 }, 
    { social_name: 'A', social_image_url: '.....', score: 2 } ] 

bekommen Ich habe zwei Aufzeichnungen social_name: A anstatt es nur max bekommen davon

{ social_name: 'A', social_image_url: '.....', score: 3 } 

Antwort

0

Ich löse dies endlich durch Erstellen von Unterabfrage fi zuerst und dann verwenden Sie diese innere Verbindung mit ihm.

Verwandte Themen