繁体   English   中英

在“ SAS” proc sql中左联接中的“ IF”条件

[英]“IF” condition in left join in “SAS” proc sql

我有一个表a ,其中包含列a1a2

我有一个表b ,其中包含列b1b2

我想left join bacondition1 ,如果a2 is nullcondition2 ,如果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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM