Sql Server查询表内重复字段的个数

语法如下:

  SELECT [字段名],COUNT(1) FROM [表名] Group By [字段名] Having Count(1) > 1

  如下图所示,我们要查询表内年龄重复的个数

  

  SELECT Age,COUNT(1) AS RepeatData FROM Student Group by Age having COUNT(1)>1

  

  Group by :根据什么进行分组,上面那句话的意思就是根据 Age 分组;

  Having:筛选满足条件的组,就是在分组之后过滤数据;查询结果为什么没有Age为23的?答:因为后面写了 Having Count(1) > 1;

posted @ 2019-04-15 22:10  大北票  阅读(2631)  评论(0编辑  收藏  举报