count(*) count(1) count(id)

  • select count(*) from table
    表示返回表中包括空行和重复行在内的行数,但是会扫描所有列。
  • select count(1) from table
    也是返回表中包括空行和重复行在内的行数,不会扫描所有列,1其实就是表示有多少个符合条件的行,但是此时没有where,所有没条件也就是返回总行数。
  • select count(id) from table
    表示返回表中存在该列id的行数,但是该列的值不为空,为空的不计算。
发布了19 篇原创文章 · 获赞 1 · 访问量 270

猜你喜欢

转载自blog.csdn.net/XSemperFI/article/details/104291235