sql单表中某一字段重复,取最近3条或几条数据

时间:2021-03-16 15:14:10
select a.* from tablename a left join tablename b on a.uid=b.uid and a.id>=b.id group by a.id,a.name,a.uid having count(b.id)<=3 order by a.uid,a.id;

sql查询语句,针对需求:一个表中某一字段是有重复的数据,针对该字段相同的值只取最近的3条或要求的几条;

 

 

              --记录铭心!