语法如下:
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;
原文地址:https://www.cnblogs.com/MrDiaobaba/p/10713608.html
时间: 2024-10-21 12:26:27