1

我正在尝试使用奥林匹克数据库,我的任务是修改我所知道的有关在同一赛事中并列的奥运选手的信息。

“首先,扩展查询以显示有关事件的更多详细信息:代替事件 ID,显示事件性别、距离和样式。作为其中的一部分,现在将按事件性别、距离、样式。然后放置。

其次,显示两个参赛者的更多细节:在每个参赛者编号的位置,显示他们的名字和姓氏以及他们的国家名称(而不是国家代码)。”


我必须使用的四个表是:

竞争对手,其中包含:CompetitornNum、Givenname、Familyname。

结果,其中包含:Eventid、CompetitorNum、Place。

事件,其中包含:Eventid、Eventgender、Distance、Style

国家,其中包含:国名

Is my original query.

SELECT C1.EventID, C1.Place, C1.CompetitorNum, C2.CompetitorNum
FROM Results C1, Results C2
WHERE C1.Place = C2.Place
    and C1.EventID = C2.EventId
    and C1.CompetitorNum < C2.CompetitorNum
ORDER BY C1.EventID;

我的问题是我对我需要做什么有一个概念,但是每次我尝试某些东西时我们被告知要使用的程序崩溃,我真的不知道从哪里开始。

SELECT Eventgender, Distance, Style, C1.Place, Givenname, Familyname, Countryname,     Givenname, Familyname, Countryname
FROM Results C1, Results C2
    natural join Competitors
    natural join Countries
    natural join Events
WHERE C1.Place = C2.Place
    and C1.EventId = C2.EventId
    and C1.CompetitorNum < C2.CompetitorNum
ORDER BY C1.EventID;

我希望选择第 1 个人和第 2 个人的 Givenname、Familyname 和 Countryname,而不是我目前正在检索的 CompetitorNum。

我的新查询找到了第一个人,但我不确定如何更改以获取第二个人信息。

任何帮助将不胜感激


我似乎找到了解决方案,但是我不确定我是否使用了最好的方法来完成任务。有更好的方法吗?

SELECT C5.Eventgender, C5.Distance, C5.Style, C1.Place, C3.Givenname, 
C3.Familyname, C6.Countryname, C4.Givenname, C4.Familyname, C7.Countryname
FROM Results C1
    join Results C2 on C1.Place = C2.Place and C1.EventId = C2.Eventid 
        and C1.Competitornum < C2.Competitornum
    join Competitors C3 on C3.Competitornum = C1.Competitornum
    join Competitors C4 on C4.Competitornum = C2.Competitornum
    join Events C5 on C5.Eventid = C1.Eventid
    join Countries C6 on C6.Countrycode = C3.Countrycode
    join Countries C7 on C7.Countrycode = C4.Countrycode
ORDER BY C1.EventId;
4

1 回答 1

0
SELECT C5.Eventgender, C5.Distance, C5.Style, C1.Place, C3.Givenname, 
C3.Familyname, C6.Countryname, C4.Givenname, C4.Familyname, C7.Countryname
FROM Results C1
    INNER JOIN Results C2 on C1.Place = C2.Place and C1.EventId = C2.Eventid 
        and C1.Competitornum < C2.Competitornum
    INNER JOIN Competitors C3 on C3.Competitornum = C1.Competitornum
    INNER JOIN Competitors C4 on C4.Competitornum = C2.Competitornum
    INNER JOIN Events C5 on C5.Eventid = C1.Eventid
    INNER JOIN Countries C6 on C6.Countrycode = C3.Countrycode
    INNER JOIN Countries C7 on C7.Countrycode = C4.Countrycode
ORDER BY C1.EventId;
于 2012-09-14T03:05:20.933 回答