Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有人知道如何优化下面的查询,因为它需要相当长的时间:
select count(*) from (select field1 from table group by field1 having count(distinct field1) <> count(field1)) AS Q1
该查询用于查找列中非唯一值的数量。
如果您想要非唯一值的数量,请使用:
select count(*) from (select field1 from table group by field1 having count(*) > 1 ) t
而且,是的,索引table.field1会加快这一进程。
table.field1
如果您想要这些值,请使用:
select field1 from table group by field1 having count(*) > 1
添加一个INDEXon 列field1,例如
INDEX
field1
ALTER TABLE tableNAME ADD INDEX (field1)