Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 优化sql查询以查找列中非唯一值的数量_Mysql_Sql - Fatal编程技术网

Mysql 优化sql查询以查找列中非唯一值的数量

Mysql 优化sql查询以查找列中非唯一值的数量,mysql,sql,Mysql,Sql,是否有人知道如何选择下面的查询,因为它需要相当长的时间: select count(*) from (select field1 from table group by field1 having count(distinct field1) <> count(field1)) AS Q1 查询用于查找列中非唯一值的数量。在列字段1上添加索引,例如 在列字段1上添加索引,例如 如果需要非唯一值的数量,请使用: select count(*) from (select field1

是否有人知道如何选择下面的查询,因为它需要相当长的时间:

select count(*) from 
(select field1
from table
group by field1
having count(distinct field1) <> count(field1)) AS Q1
查询用于查找列中非唯一值的数量。

在列字段1上添加索引,例如

在列字段1上添加索引,例如


如果需要非唯一值的数量,请使用:

select count(*)
from (select field1
      from table
       group by field1
       having count(*) > 1
      ) t
select field1
from table
group by field1
having count(*) > 1
是的,table.field1上的索引将加快速度

如果需要这些值,请使用:

select count(*)
from (select field1
      from table
       group by field1
       having count(*) > 1
      ) t
select field1
from table
group by field1
having count(*) > 1

如果需要非唯一值的数量,请使用:

select count(*)
from (select field1
      from table
       group by field1
       having count(*) > 1
      ) t
select field1
from table
group by field1
having count(*) > 1
是的,table.field1上的索引将加快速度

如果需要这些值,请使用:

select count(*)
from (select field1
      from table
       group by field1
       having count(*) > 1
      ) t
select field1
from table
group by field1
having count(*) > 1

如果没有索引,即使你有一个好的查询,性能仍然很低。如果没有索引,即使你有一个好的查询,性能仍然很低。