ChineseMoonGod

对于统计count(type)和avg(type) 都不起作用

SQL中有ISNULL方法,介绍如下:

ISNULL
使用指定的替换值替换 NULL。

语法
ISNULL ( check_expression , replacement_value )

参数

check_expression
将被检查是否为 NULL的表达式。check_expression 可以是任何类型的。
replacement_value
在 check_expression 为 NULL时将返回的表达式。replacement_value 必须与 check_expresssion 具有相同的类型。

例如:

SELECT count(ISNULL(Weight, 50))  FROM  Product;

但是在mysql中,isnull只是用来判断是否为空,不能实现替换功能,照上面写的话,会直接报错(Incorrect parameter count in the call to native function \'isnull\' Errornumber:1582 )。

那么Mysql中如何实现SQL中的ISNULL方法呢?IFNULL( check_expression , replacement_value ),实现了SQL中的ISNULL方法。

 还是上面的例子:

SELECT count(IFNULL(Weight, 50))  FROM  Product;

就好了,就这样。

分类:

技术点:

相关文章:

  • 2021-12-10
  • 2021-12-04
  • 2021-12-20
  • 2022-01-07
  • 2021-12-10
  • 2021-12-04
  • 2021-07-21
  • 2022-01-20
猜你喜欢
  • 2022-01-07
  • 2021-08-31
  • 2021-11-27
  • 2021-12-10
  • 2022-01-07
相关资源
相似解决方案