1.count(1)

  • 返回为0

    如果所查询的表或者where条件筛选后得到的结果集为空,则 count(1)返回为 0

    如:

    select count(id) from test;

    select count(id) from test where id < 0;

  • 返回为NULL

    如果所查询的表或者where条件筛选后得到的结果集为空且当前层查询中使用了group by ,则 count(1)返回为 NULL

    如:

    select count(id) from test group by id;

    select count(id) from test where id < 0 group by id;

2.sum(1)

  • 返回为NULL

    如果所查询的表或者where条件筛选后得到的结果集为空 ,则 sum(1)返回为 NULL

    如:

    select sum(id) from test;

    select sum(id) from test where id < 0;

注:如果想NULL转为0返回可以使用IFNULL(expression_1,expression_2);表示如果expression_1不为NULL,则IFNULL函数返回expression_1; 否则返回expression_2的结果。

如IFNULL(sum(id),0)

最新文章

  1. HTML ------ 关于表单 Form
  2. ArcEngine 栅格数据
  3. Form提交是会刷新页面的
  4. POJ1285 Combinations, Once Again(背包 排列组合)
  5. react native 底部按钮切换
  6. 【转】JSONP简介
  7. CodeSmith使用总结--创建一个基础模板
  8. SQL Server 移动master 数据库
  9. poj 1679 The Unique MST 【次小生成树】【模板】
  10. call 和 ret 指令
  11. js备战春招の四のdevtool中各种错误、调试的使用技巧
  12. [SCOI2015]国旗计划
  13. 迷宫问题 (bfs广度优先搜索记录路径)
  14. (1)Java数据结构--图文并茂-分析优缺点
  15. python 读写、创建 文件的方法(必看)
  16. C++模拟键盘消息
  17. busybox microcom Segmentation fault
  18. [TJOI2018]智力竞赛
  19. Spring框架第三篇之基于XML的DI注入
  20. Sqlalchemy 设置表编码及引擎

热门文章

  1. POJ 1015 Jury Compromise dp
  2. Docker:Docker常用命令
  3. redis广播/订阅模式演示
  4. linux cut的用法
  5. 【分布式】CAP理论及其应用
  6. C语言:宏定义
  7. win10禁止粘滞键 禁止按5次shift开启粘滞键
  8. Python3.7 lxml引入etree
  9. linux xsel命令
  10. Xshell、winscp连不上Linux虚拟机