新手;运行排名数据库

时间:2017-02-01 15:36:16

标签: php-mysqlidb

我有2张桌子。一个有结果,一个有运动员。当我跑步时,列出每个运动员的每一个结果。我如何从每位运动员那里获得最快的时间?在下面的例子中,我只想要Reed Brown最快的时间。

id  place   athlete_id  grade   team_id             time    event
126 3      Reed Brown   11      TEXAS               4:01.99 1600m
127 1      Reed Brown   11      Southlake Carroll   4:07.17 1600m
95  1      Reed Brown   11      Southlake Carroll   4:07.17 1600m
128 2      Bryce Hoppel 12      Midland Senior      4:15.12 1600m
96  2      Bryce Hoppel 12      Midland Senior H    4:15.12 1600m

1 个答案:

答案 0 :(得分:2)

尝试以下方法:

Select per.*
From performances per
Inner Join
(
  Select athlete_id, MIN(time) AS fastesttime 
  From performances 
  Group By athlete_id
)per1
On per1.athlete_id=per.athlete_id
Where per1.fastesttime=per.time