mysql - 计算重复记录的数量

标签 mysql crystal-reports

我的子报告遍历 ID 列表。每个 ID 都分配有一个位置。该报告按位置(组 #1)分组,然后按 ID(组 #2)分组。

在表中,ID 应如下所示:

14600
14602
14602
14602
14700
14703
14704
14704

我想要的输出是2,因为有 2 个 ID 具有多个条目。我怎样才能轻松计算出这个值?

最佳答案

你可以试试这个:

 DECLARE @temp table(num integer);

 INSERT INTO @temp(num) VALUES (14600), (14602), (14602), (14602), (14700), (14703), (14704), (14704);

 SELECT COUNT(distinct num) repeats
 FROM
     (SELECT
        num, count(num) as counts
      FROM @temp
      GROUP BY num 
      HAVING COUNT(num) > 1) a; 

关于mysql - 计算重复记录的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44534453/

相关文章:

php - 如何使用mysql和php在指定的日期和时间发送邮件

asp.net - 我可以修改Request.Headers集合吗?

c# - 如何在 C# Crystal 报表中总结具有十进制值的列

asp.net - Crystal 报表 : "Failed to Save Document" after changing Datasource

Php mysql 查询在 chrome 中有效,但在 firefox/IE 中无效

mysql - 脚本出现错误

php - 如何在 ng-repeat 中使用 ng-class 为每个迭代 div 设置类

mysql - ASP.NET MVC 和 MySQL 作为网站的框架选择

mysql - Crystal 报表4.6.1.0连接Mysql

c# - Crystal Report WinForm如何修复它错误对象引用未设置为对象的实例?