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条或要求的几条;
--记录铭心!
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条或要求的几条;
--记录铭心!
转载于:https://www.cnblogs.com/xinloverong/p/5161243.html