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;
答案 0 :(得分:3)
三个表之间没有joins,因此您将获得一个笛卡尔积。尝试切换到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;