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
如果没有索引,即使你有一个好的查询,性能仍然很低。如果没有索引,即使你有一个好的查询,性能仍然很低。