思路:
在表中6,7号数据,他们的除了ID不同,其他的数据相同;首先,在表中找到一个组合主键,然后以主键group by 然后计算出大于1的记录,然后在通过组合主键找到这条记录,然后就能把记录找到了。就找了两条相同的记录,
select * from tb_stu as t join (select count(*) as amount, t5.stuId, t5.stuName from (select * from tb_stu as s) as t5 group by stuId , t5.stuName) as t5 ON t.stuId = t5.stuId and t.stuName = t5.stuName where t5.amount > 1
其实还可以这样理解,查找除了主键id不想同,但是其余数据均相同的其他数据
select t.id from tb_stu as t
join tb_stu as s
on t.stuId = s.stuId and t.stuName = s.stuName
and t.stuClass = s.stuClass and t.id!=s.id;
通过上面的代码可以求出id,id都出来那么就很好求这条记录了
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/4670.html