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