mysql通过分组条件,取得分个条件中的最后一条记录。

直接上代码:

1、group_concat

select SUBSTRING_INDEX(group_concat(id order by id desc),',',2) id from content c
where  c.grouperid in (1,2)
GROUP BY c.grouperid in (1,2);

 

 2、max

select max(id) as id from content where grouperid in (1,2) 
group by grouperid

 

有了id,那么下面就好办了, 自由发挥。

 

posted @ 2021-07-26 15:53  jiduoduo  阅读(812)  评论(0)    收藏  举报