0
我有一個表a
,它包含列a1
和a2
。「IF」條件左加入「SAS」進程sql
我有一個表b
,其中包含列b1
和b2
。
我想left join
b
到a
上condition1
如果a2 is null
和condition2
如果a2 is not null
。
我該如何構造這個查詢?
我有一個表a
,它包含列a1
和a2
。「IF」條件左加入「SAS」進程sql
我有一個表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);
樣本數據和期望的結果將有助於闡明您想要執行的操作。 –