标签:
用一个简单的例子讲解。
场景:显示每列火车最晚到达时间的记录。
Train Dest Time
1 HK 10:00
1 SH 12:00
1 SZ 14:00
2 HK 13:00
2 SH 09:00
2 SZ 07:00
Train Dest Time
1 SZ 14:00
2 HK 13:00
SELECT t.Train, t.Dest, r.MaxTime FROM ( SELECT Train, MAX(Time) as MaxTime FROM TrainTable GROUP BY Train ) r INNER JOIN TrainTable t ON t.Train = r.Train AND t.Time = r.MaxTime
(完)
标签:
原文地址:http://www.cnblogs.com/lin-xuan/p/5436106.html