我有一个具有以下结构和数据的mysql表。我想显示任何ID上最后插入的记录。

id    lc_counter       lc_timestamp
1     15               2013-03-01 11:54:43
1     13               2013-03-01 11:48:56
10    7                2013-03-01 11:54:43
10    5                2013-03-01 11:48:56
100   5                2013-03-01 11:54:43
100   3                2013-03-01 11:54:43


SELECT inv_id, lc_counter, lc_timestamp
FROM link_counter
group by inv_id
order by inv_id asc, lc_timestamp desc


我想得到这个结果:

id    lc_counter       lc_timestamp
1     15               2013-03-01 11:54:43
10    7                2013-03-01 11:54:43
100   5                2013-03-01 11:54:43

最佳答案

Select link_counter.lc_counter, MAX(link_counter.lc_timestamp)
 from link_counter group by link_counter.id

08-04 17:20