SQL查询语句

来源:互联网 发布:淘宝购买mycard 编辑:程序博客网 时间:2024/05/18 01:25

先开个帖子,慢慢补充,测试环境均为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;

原创粉丝点击