我試圖獲得前五名玩家,我使用join來獲取personId上的每個玩家信息庫,但是我的查詢返回重複數據。我無法弄清楚它爲什麼重複記錄,任何幫助都會非常受歡迎。由於Laravel加入返回重複數據
DB::table('person_competition_statistics as pcs')
->where('pcs.competitionId', $competitionId)
->where('pcs.teamId', $teamId)
->orderBy('pcs.sStealsAverage', 'desc')
->rightJoin('players as player', 'pcs.personId', '=', 'player.personId')
->select(['pcs.personId', 'pcs.sStealsAverage', 'player.firstName', 'player.familyName', 'player.playingPosition', 'player.image_thumb'])
->take(5)
->get();
下面是結果
#items: array:5 [▼
0 => {#444 ▼
+"personId": 29872
+"sStealsAverage": 1.24
+"firstName": "Rhys"
+"familyName": ""
+"playingPosition": ""
+"image_thumb": ""
}
1 => {#438 ▼
+"personId": 29872
+"sStealsAverage": 1.24
+"firstName": "Rhys"
+"familyName": ""
+"playingPosition": ""
+"image_thumb": ""
}
2 => {#439 ▼
+"personId": 29872
+"sStealsAverage": 1.24
+"firstName": "Rhys"
+"familyName": ""
+"playingPosition": "GRD"
+"image_thumb": ""
}
3 => {#441 ▼
+"personId": 29872
+"sStealsAverage": 1.24
+"firstName": "Rhys"
+"familyName": ""
+"playingPosition": "GRD"
+"image_thumb": ""
}
4 => {#435 ▼
+"personId": 29872
+"sStealsAverage": 1.24
+"firstName": "Rhys"
+"familyName": ""
+"playingPosition": "GRD"
+"image_thumb": ""
}
添加'groupBy'。 –
添加一個獨特的並刪除'playingPosition',否則你將仍然有重複。 –
您可以通過 –