MySQL 我可以同时使用 COUNT() 和 DISTINCT 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4483798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:03:18 来源:igfitidea点击:
Can I use COUNT() and DISTINCT together?
提问by Adamski
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()
?
我可以distinct
用count()
吗?
回答by BoltClock
Sure.
当然。
SELECT COUNT(DISTINCT column) FROM table;
回答by Ivan Torres
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
回答by Avanish Kumar
SELECT count(DISTINCT column Name) as alias from table_Name;