[英]“IF” condition in left join in “SAS” proc sql
我有一个表a
,其中包含列a1
和a2
。
我有一个表b
,其中包含列b1
和b2
。
我想left join
b
到a
在condition1
,如果a2 is null
和condition2
,如果a2 is not null
。
如何构造此查询?
如果我正确理解:
proc sql;
select . . .
from a left join
b
on (a2 is null and condition1) or
(a2 is not null and condition2);
这是您要求的直接翻译。 通常,以下各项通常具有更好的性能,因为它可以更好地利用索引(取决于条件的性质):
proc sql;
select a.*, coalesce(b1.b2, b2.b2) as b2
from a left join
b b1
on (a2 is null and condition1) left join
b b2
on (a2 is not null and condition2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.