mysql coalesce函数与 ifnull 函数对比

# coalesce: 联合,合并。返回传入的参数中第一个非null的值
SELECT
	COALESCE (NULL, NULL, 1, 2);

# 如果只有两个参数和IFNULL用法一样, 1 , 1 , 1 , NULL
SELECT
	IFNULL(NULL, 1) as ifnull,
	COALESCE (NULL, 1) as coalesceTwo,
	COALESCE (NULL, NULL, 1, 2) as coalesceFour,
	COALESCE (NULL, NULL, NULL, NULL) as coalesceAllNull;

 
mysql coalesce函数与 ifnull 函数对比_第1张图片
 

你可能感兴趣的:(mysql)