我可以一起使用COUNT()和DISTINCT吗?

时间:2022-11-25 18:01:27

I would like to count the number of rows from a mysql table and not to include duplicate entries,

我想计算mysql表中的行数,而不是包含重复的条目,

Could I use distinct with count()?

我可以使用与count()的distinct吗?

4 个解决方案

#1


37  

Sure.

当然。

SELECT COUNT(DISTINCT column) FROM table;

#2


9  

What you need is the following:

您需要的是以下内容:

SELECT field_type_name, count(*) FROM fields GROUP BY field_type_name;

This will give you something like this:

这会给你这样的东西:

image   14
string  75
text     9

#3


5  

 SELECT COUNT(DISTINCT field) from Table

See this.

看到这个。

#4


0  

SELECT count(DISTINCT column Name) as alias from table_Name;

#1


37  

Sure.

当然。

SELECT COUNT(DISTINCT column) FROM table;

#2


9  

What you need is the following:

您需要的是以下内容:

SELECT field_type_name, count(*) FROM fields GROUP BY field_type_name;

This will give you something like this:

这会给你这样的东西:

image   14
string  75
text     9

#3


5  

 SELECT COUNT(DISTINCT field) from Table

See this.

看到这个。

#4


0  

SELECT count(DISTINCT column Name) as alias from table_Name;