1.表结构与数据: CREATE TABLE tablezzl( id int, name ) ); 2.查询出重复的数据: 3.查询出要保留的重复数据: 4.最终的SQL: DELETE FROM tablezzl ) ) a) ) ) b) 5.补充 : 其中这样写mysql中不能如下这样写: DELETE FROM tablezzl ) ) 会报错:You can't specify target table 'tablezzl' for update in FROM clause,不能在
create table test (id int, name ), score int, classname )); ,,'一班'); ,,'一班'); ,,'一班'); ,,'二班'); ,,'二班'); ,,'二班'); select t.* from (select test.*,row_number() over (partition by classname order by score desc) rn from test) t ;