1.返回第一个非空数值
SELECT COALESCE(NULL, NULL, NULL, 'W3Schools.com', NULL, 'Example.com');
返回:W3Schools.com
SELECT COALESCE(NULL, 1, 2, 'W3Schools.com');
返回:1
应用:将一个字段中空值全部替换为指定的数值
select gid, toid, coalesce(device_type,3)as from_id from test
--表示将device_type字段的空值全部改为3,并重新命名为from_id
2.将某一字段全部用同一数值表示
select id, source, target , 1 as cost ,1 as reverse_cost from test