简体   繁体   中英

Can I use COUNT() and DISTINCT together?

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

Could I use distinct with count() ?

当然。

SELECT COUNT(DISTINCT column) FROM table;

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
 SELECT COUNT(DISTINCT field) from Table

看到这个

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM