56,679
社区成员
发帖
与我相关
我的任务
分享
mysql> select * from student a where not exists (select 1 from student where classid=
-> a.classid and id>a.id) order by id desc;
+------+-------------+---------+
| id | name | classid |
+------+-------------+---------+
| 6 | wangwu | 4 |
| 5 | lisi | 3 |
| 4 | zhangsan | 2 |
| 2 | yuanyongzhi | 1 |
+------+-------------+---------+
select max(id) as id,name,classid from student order by classid desc
select max(id) as id,name,classid from tb order by classid desc
select *
from student s
where not exists(select 1 from student where classid=s.classid and id>s.id)