如果我有这样的数据:
+---+----+ |Key|Name| +---+----+ |1 |Dan | +---+----+ |2 |Tom | +---+----+ |3 |Jon | +---+----+ |4 |Tom | +---+----+ |5 |Sam | +---+----+ |6 |Dan | +---+----+
所以我想要的结果是
+---+ |Tom| +---+ |Dan| +---+
解决方法
不能简单…
Select Name,Count(Name) As Count From Table Group By Name Having Count(Name) > 1 Order By Count(Name) Desc
这也可以扩展到删除重复项:
Delete From Table Where Key In ( Select Max(Key) From Table Group By Name Having Count(Name) > 1)