如下的图片,请问要如何实现呢?
补充,希望实现如下,我会将最后的日期的 值及文字代出来
select * from table as t
where (select count(distinct(t1.日期)) from table as t1 where t1.id =t.id and t1.日期 > t.日期) < 1
SELECT * FROM (SELECT * from `table` ORDER BY id desc)t GROUP BY `name`
select * from 表名 where 日期 in(select max(日期) from 表名 group by ID)
请采纳
select a.* from tableName a join (select ID ,max(date) from tableName group by ID ) b on a.ID=b.ID and a.date=b.date
问题的关键是筛选出所有ID中最近的日期所有信息,所以我们需要日期加ID来唯一确定一条数据,所以思路是先遍历出所有满足条件的日期和ID再回查原表,找出对应的数据
select a.ID,a.date,num,text from question a right join (select ID,max(date) as date from question group by ID) as b on a.ID=b.ID and a.date=b.date