select * from (select t.*,row_number() over(partition by id order by history desc) rn from tablename) where rn = 1
select a.* from tablename a,(select id,max(history) from tablename group by id) b where a.id = b.id and a.history = b.history;
漏了别名: select * from (select t.*,row_number() over(partition by id order by history desc) rn from tablename t) where rn = 1
select * from test s where rowid in (select max(rowid) from test group by id)
select * from tablename where rowid in (select max(rowid) from test group by id)
呵呵。。还是把表名写错了 select * from tablename s where rowid in (select max(rowid) from tablename group by id)
如果要取第一到第二条: select a.* from tablename a,(select id,max(history)as history2 from tablename group by id) b where a.id = b.id and a.history = b.history2 and rownum <= 2
select * from tablename where (id,history) in (select id,max(history) history from tablename group by id) order by id;
select id,max(name),max(history) from tablename group by id
where a.id = b.id
and a.history = b.history;
select * from (select t.*,row_number() over(partition by id order by history desc) rn from tablename t) where rn = 1
select * from tablename s where rowid in (select max(rowid) from tablename group by id)
select a.* from tablename a,(select id,max(history)as history2 from tablename group by id) b
where a.id = b.id
and a.history = b.history2
and rownum <= 2
from tablename
group by id