1
问题描述:
记录情况像这样:
court_id log_id date
2 34 2005-01-01
2 56 2005-03-09
4 37 2005-07-07
4 78 2005-07-21
6 48 2005-04-09
我想取出的结果是:
court_id log_id date
2 56 2005-03-09
4 78 2005-07-21
6 48 2005-04-09
也就是court_id相同的记录则取其date 最晚的一条记录()
log_id 为pk 自增 ,说明白了吗?
问题解答:
select * from table where log_id in(select max(log_id) from table group by court_id )
博客提出一个SQL问题,给定记录包含court_id、log_id和date,要求取出court_id相同记录中date最晚的一条。并给出了解答,使用SQL语句“select * from table where log_id in(select max(log_id) from table group by court_id )”来实现。

被折叠的 条评论
为什么被折叠?



