我需要将两个表与第一个表中的所有列组合在一起(左外连接),如果四个列中的值匹配,则只需要在第二个表中组合一个列。
换句话说,如果四列匹配……
我认为 coalesce() 更简洁:
coalesce()
proc sql; create table UseLimit_updates as select . . ., coalesce(b.updatenotice, a.updatenotice, 'A') as updatenotice from work.updated_mwh a left join work.archive_dups b on a.updatenotice = b.updatenotice and a.limit_start_date = b.limit_start_date and a.limit_end_date = b.limit_end_date and a.created_date = b.created_date; end; quit;
您的代码也表明您想要 'A' 如果缺少其他值,则为默认值。
'A'
case语句必须包含在select部分中:
select case when b.updatenotice is null then a.updatenotice else b.updatenotice end, <rest of the columns of work.updated_mwh> from work.updated_mwh as a left join work.archive_dups as b on a.res_id=b.res_id and a.limit_start_date=b.limit_start_date and a.limit_end_date=b.limit_end_date and a.created_date=b.created_date end;