0

我是数据库新手。我被分配了一项与足球联赛有关的任务,其中一些球队在主场和客场比赛并存储分数等。我有以下表格

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

我需要找出最佳射手的名字,请帮忙。

4

2 回答 2

1

ifgoals.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;
于 2013-11-03T08:02:44.037 回答
0
select  people_first_name people_last_name
from people
where people_id not in(
    select A.id
    from(
        select goal_player_people_id as id,count(*) as gc
        form goals
        group by goal_player_people_id) A,
        (
        select goal_player_people_id as id,count(*) as gc
        form goals
        group by goal_player_people_id) B,
    where A.gc<B.gc
)
于 2013-11-03T05:48:28.667 回答