我们一般情况下通过分组函数group by来查询重复的列
SELECT [column1],[column2] FROM [dbo].[Table] where 1=1) R group by [column1],[column2] having count(*) > 1
但是查询出的结果不能显示该表的其他列
想要查询一张表中有多个列重复的数据且也要显示该表的其他列
SELECT M.* FROM [dbo].[Table] M, (SELECT * FROM (SELECT [column1],[column2] FROM [dbo].[Table] where 1=1) R group by [column1],[column2] having count(*) > 1) M1 where M.[column1]=M1.[column1] AND M.[column2]=M1.[column2]
原文地址:https://www.cnblogs.com/ruanraun/p/groupby.html
时间: 2024-10-10 04:46:37