MySQL COUNT()和null [英] MySQL COUNT() and nulls
本文介绍了MySQL COUNT()和null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是否正确地说:
COUNT(expr)
WHERE expr IS NOT *
仅计算非null吗?
Will count only non nulls?
COUNT(*)
始终计数所有行吗?而且如果所有列都为空怎么办?
Will COUNT(*)
always count all rows? And What if all columns are null?
推荐答案
正确. COUNT(*)是表中的所有行,COUNT(Expression)是表达式仅非空的地方.
Correct. COUNT(*) is all rows in the table, COUNT(Expression) is where the expression is non-null only.
如果所有列均为NULL(表示您没有主键,那么这在规范化数据库中就不会发生)COUNT(*) still 返回所有插入的行.只是不要那样做.
If all columns are NULL (which indicates you don't have a primary key, so this shouldn't happen in a normalized database) COUNT(*) still returns all of the rows inserted. Just don't do that.
您可以将*符号认为是在表格中"而不是在任何列中".
You can think of the * symbol as meaning "in the table" and not "in any column".
这篇关于MySQL COUNT()和null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文