码迷,mamicode.com
首页 > 其他好文 > 详细

count和distinct

时间:2018-08-02 20:41:40      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:常见   一个   去掉   写法   null   忽略   from   重复   rom   

一.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)不一定一致。

count和distinct

标签:常见   一个   去掉   写法   null   忽略   from   重复   rom   

原文地址:https://www.cnblogs.com/lxyit/p/9409278.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!