先开个帖子,慢慢补充,测试环境均为MYSQL。
1 选出name列有重复的行
select * from Table group by name having count(*) > 1;
2 选出score列的值排前3名的行
这里有个陷阱就是,值排前三名,对应的行可能多于三行,要把它们都选出来。
select * from Table a where (select count(*) from Table where score > a.score) < 3;