test表 |
|
40分 |
select max(id) id , tid from table group by tid order by id
|
— 用DESC倒序
SELECT * FROM TAB AS a WHERE NOT EXISTS ( SELECT 1 FROM TAB WHERE tid = a.tid AND id > a.id ) ORDER BY id DESC |
|
select max(id) ,tid from test GROUP BY tid order by max(id) DESC ; |
|
版主 你写的和其它网友写的 哪个效率高些呢? |
|
具体看执行计划,如以楼主的例子只显示两列,用1#直接group by就行了,如实际是有多列显示条件不变时用where |