当前位置: 代码迷 >> Sql Server >> 请问一个分组求最大值的SQL语句!(内详)
  详细解决方案

请问一个分组求最大值的SQL语句!(内详)

热度:88   发布时间:2016-04-27 19:47:14.0
请教一个分组求最大值的SQL语句!(内详)
表结构:
id           carId             dateChange
1               001                   2007-5-1
2               001                   2007-5-2
3               002                   2007-9-1
4               002                   2007-9-9
需要得到每种carId中,dateChange最大的那条记录,对于现在这几条记录来说,就是要得到第2条和第四条。
谢谢!!!

------解决方案--------------------
select
t.*
from
表 t
where
t.dateChang=(select max(dateChange) from 表 where carId=t.carId)
  相关解决方案