在mysql中,我需要一个查询来返回表“Log”的“Info”字段中重复值的数量。
表日志:
ID_Log User Info
1 1 3
2 1 3
3 1 3
4 1 5
5 1 6
6 1 6
7 1 7
8 1 8
9 1 8
查询应返回“4”(Info 3 出现三次,Info 6 出现两次,Info 8 出现两次)。
有什么建议吗?
最佳答案
您可以通过简单的减法获得已经出现的值的数量。从总行数中减去不同值的数量:
select count(*) - count(distinct info)
from log;
区别在于“重复”的数量。
关于mysql - 返回重复值数量的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23143484/