1
我有一个像这样设置的较量的MySQL表。如何结合具有类似时间戳的两行并返回两个
|------------------------|
|bouts |
|------------------------|
|boutID |
|recording_athlete |
|boutdate (timestamp) |
|opponent |
|recording_athlete_points|
|------------------------|
两个人之间的每个实际会在表中记录了两次,有独特的boutID和boutdate(反映的那一刻时,它实际上是输入,但5分钟等之内)和一个的记录运动员是另一方的反对者,反之亦然。这两个记录不一定是连续的。每天有两个参加者会议,间隔较长的时间间隔:我们正在寻找时间戳和身份证号码中最接近的两个(假设这两个属于一起)。
我想选择属于连成一排(和实现,并希望它会做两次)这样的记录,它会输出匹配的行是这样的:
boutID|recording_athlete|boutdate|opponent|recording_athlete_points|boutID_b|boutdate_b|opponent_points
01|John|2012-05-10 20:33:04|Jane|15|04|2012-05-10 20:36:12|10
04|Jane|2012-05-10 20:36:12|John|10|01|2012-05-10 20:33:04|15
这里是我的到目前为止,我认为我需要去,但只是无法弄清楚要使用什么。某种间隔陈述?或者我需要一个完全不同的结构?
SELECT
A.`boutID`,
A.`recording_athlete`,
A.`boutDate`,
A.`opponent`,
A.`recording_athlete_points`,
B.`boutID` as `boutID_b`,
B.`boutDate` as `boutdate_b`,
B.`recording_athlete_points`as `opponent_points`
FROM bouts A
INNER JOIN bouts B on(A.`fullName` = B.`opponent` AND ?????)
ORDER by A.`boutDate`
正确地匹配在一起,所有的时间不,它不是返回东西。 –