count和distinct

一.count和distinct

count是统计数据条数,distinct是去掉重复列;

count统计的时候会忽略null值,distinct会将重复的null值列作为一个。

综上select count(null) from table,结果永远是0。

二.count的几种形式

常见到count(*),count(1),count(field)的统计写法,这里记录下区别:

  • count(*): 统计表中所有的行数,包括null值的列;
  • count(1): 同count(*)
  • count(field): 在列上统计个数,会忽略null值

综上,count(*)和count(1)结果一致,和count(field)不一定一致。

posted @ 2018-08-02 19:09  怀瑾握瑜XI  阅读(1480)  评论(0编辑  收藏  举报