我是数据库新手。我得到的任务与足球联赛有关,在足球联赛中,一些球队在主场和客场进行比赛,并存储得分等,等等。我有下表
goals
======================
goal_id
goal_player_people_id
goal_game_id
goal_score
player
=====================
player_people_id
player_team_id
people
====================
people_id
people_first_name
people_last_name
people_dob
我需要找出得分王的名字,请帮忙。
最佳答案
如果goals.goal_player_people_id
是对people.people_id
的引用:
SELECT p.people_first_name, p.people_last_name, SUM(g.goal_score) totscore
FROM goals g
JOIN people p
ON g.goal_player_people_id = p.people_id
GROUP BY p.people_id
ORDER BY totscore DESC LIMIT 1;