0
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

以下查询允许从假设表“结果”中显示在某项赛事中并列的参赛者。即在一个事件中获得相同的位置。

我需要扩展查询以显示有关事件的更多详细信息 - 代替事件 ID,我需要显示来自假设的其他/第二个表“事件”的事件性别、距离和样式。

如何扩展查询以包含事件表中的必要信息?

4

2 回答 2

1

我假设在 Events 表中有一个 Eventid 列。

SELECT X.*, e.eventgender, e.distance , e.style
FROM Events e
INNER JOIN
        (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)X
ON x.Eventid = e.Eventid
于 2012-09-12T08:11:34.287 回答
1

要显示来自相关表的数据,您可以使用JOIN它们。

Select e.eventgender, e.distance, e.style, 
       c1.Place, c1.competitornum, 
       c2.competitornum
From Results c1, Results c2
LEFT OUTER JOIN Events e ON e.Eventid = c1.Eventid
Where c1.Place = c2.Place
and c1.Eventid = c2.Eventid
and c1.competitornum < c2.competitornum
于 2012-09-12T07:24:55.280 回答