mysqlcountdistinctnull使用注意事项_MySQL
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mysqlcountdistinctnull使用注意事项_MySQL,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1021字,纯文字阅读大概需要2分钟。
内容图文
![mysqlcountdistinctnull使用注意事项_MySQL](/upload/InfoBanner/zyjiaocheng/574/ea8b515df6894130873e92bbcbae94c0.jpg)
mysql count distinct null使用注意事项
1 用一个例子来讲解一个问题,现在又一个库表hello,表内容如下:
id name
1 Null
2 Null
3 Null
4 Null
5 Null
hello表一共两个字段:id和name,name is null。
第一条SQL:SELECT COUNT(id) FROM hello; 查询结果:5,正确。
第二条SQL:SELECT COUNT(*) FROM hello; 查询结果:5,正确。
第三条SQL:SELECT COUNT(name) FROM hello; 查询结果:0,错误。
第四条SQL:SELECT COUNT(DISTINCT id,name) FROM hello;查询结果:0,错误。
2 第二条SQL和第三条SQL查询错误的原因:
2.1 COUNT(), MIN(), and SUM() ignore NULL values.
2.2 The exception to this is COUNT(*), which counts rows and not inpidual column values.
2.3 For example, the following statement produces two counts. The first is a count of the number of rows in the table, and the second is a count of the number of non-NULL values in the age column:
mysql> SELECT COUNT(*), COUNT(age) FROM person;
bitsCN.com
内容总结
以上是互联网集市为您收集整理的mysqlcountdistinctnull使用注意事项_MySQL全部内容,希望文章能够帮你解决mysqlcountdistinctnull使用注意事项_MySQL所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。