select * from stu where (time,name,english,chinese,math) in (select time,name,english,chinese,math from stu group by time,name,english,chinese,math has count(*)& gt; 0) and rowid in (select max (rowid) from stu group by time, name, english, chinese, math having count (*) > 0 ) ;
This is a sentence. Try this. The idea is to find max(rowid). This is the simplest method I can think of. Of course, you can write a stored procedure if you want.