Mysql 如何计算表中不同行的数量?
我试过:Mysql 如何计算表中不同行的数量?,mysql,sql,Mysql,Sql,我试过: select count(distinct *) from table_name; 但这是错误的。在我的表中没有定义为唯一的列。您可以在distinct子句中列出所有列: SELECT COUNT (DISTINCT col1, col2, etc) FROM table_name 您可以使用子选择筛选到无重复项,然后进行计数 select count(*) from (select distinct * from table_name ) t 我同意,如果没有PK
select count(distinct *) from table_name;
但这是错误的。在我的表中没有定义为唯一的列。您可以在
distinct
子句中列出所有列:
SELECT COUNT (DISTINCT col1, col2, etc)
FROM table_name
您可以使用子选择筛选到无重复项,然后进行计数
select count(*)
from (select distinct * from table_name
) t
我同意,如果没有PK,表设计可能会有问题。我认为这个查询是您的问题中最小的一个。我认为你的数据库设计是个问题