–查出表中有重复的id的记录,并计算相同id的数量 select id,count(id) from @table group by id having(count(id)1) 其中,group by id,是按id字段分组查询: select id,count(id) from @table group by id 可以得到各
–查出表中有重复的id的记录,并计算相同id的数量select id,count(id) from @table group by id having(count(id)>1)
其中,group by id,是按id字段分组查询:
select id,count(id) from @table group by id
可以得到各不同id的数量合计
having(count(id)>1)判断数量大于1,也就是有重复id的记录




![[MYSQL应用02]存储过程|存储函数](https://img.mryunwei.com/uploads/2023/07/20230719010704833.webp)