1

2012 年夏季运动会的名单,每个运动的名称和该运动的项目数量?

这就是我得到的,但它返回了一个模棱两可的答案。我究竟做错了什么?请帮忙..

SELECT
    sport_name as "Sport Name",
    COUNT(discipline_code) as "Number of Disciplines"
FROM
    GAMES.SPORT,
    GAMES.GAMESDISCIPLINE,
    GAMES.SUMMERGAMES
WHERE
    sg_year = 2012
GROUP BY
    sport_name;
4

1 回答 1

3

这三个表之间没有任何连接,因此您将获得笛卡尔积。尝试切换到 ANSI 连接语法以使其更清晰。您需要输入构成表之间连接的真实列名,我只是在这里猜测:

SELECT
    s.sport_name as "Sport Name",
    COUNT(gs.discipline_code) as "Number of Disciplines"
FROM GAMES.SUMMERGAMES sg
JOIN GAMES.GAMESDISCIPLINE gd ON gd.games_id = sg.games_id
JOIN GAMES.SPORT s ON s.discipline_id = gd.discipline_id
WHERE
    sg.sg_year = 2012
GROUP BY
    s.sport_name;
于 2012-09-11T14:26:05.200 回答