声明:
coalesce函数是一个替换函数,将值为null的替换为指定值。
HiveSQL和SQL均支持!
演示案例:
free数据库 person表
数据:id name age
1 小明 18
2 Alice 20
INSERT INTO `free`.`person` VALUES(3,'lisi',NULL);
SELECT *, COALESCE(`age`,"20") AS coal FROM `free`.`person`;
测试结果:(将age
为 null 的替换为指定值 20)