表名为A 字段 id,username,score,note
将A表里面的数据复制到B表里面,如果username相同 则取最大的score那一条数据,B表与A表结构相同。
------解决方案--------------------
- SQL code
select * from A t where not exists(select 1 from A where username=t.username and score>t.score)
------解决方案--------------------
- SQL code
insert into B表select t.id,t.username,t.score,t.notefrom(select id,username,score,note,row_number over(partition by username order by score desc) rnfrom A表) twhere t.rn=1