以下代码会产生错误:
select lastname, firstname, workphone, homephone
from members if (workphone is null) then workphone = homephone;
我正在尝试从名为 的表中选择lastnames
和firstnames
您的电话号码members
。如果成员的workphone is null
我需要将其替换为homephone
.
如果需要,我将非常乐意澄清。
以下代码会产生错误:
select lastname, firstname, workphone, homephone
from members if (workphone is null) then workphone = homephone;
我正在尝试从名为 的表中选择lastnames
和firstnames
您的电话号码members
。如果成员的workphone is null
我需要将其替换为homephone
.
如果需要,我将非常乐意澄清。
您可以使用该COALESCE
函数,它返回给定的第一个非空参数:
SELECT lastname, firstname, homephone, COALESCE(workphone, homephone) AS workphone
FROM members
select lastname, firstname,
case when (workphone is null) then homephone else workphone end as workphone
, homephone
from members;