- Inner join
Merge a(in=ina) b(in=inb);
If ina and inb
proc sql;
title "inner join equate where";
select *
from sql.Branches b inner join sql.Transact t
on b.actnum=t.actnum;
run;
- Left join
Merge a(in=ina) b(in=inb);
If ina;
proc sql;
select b.actnum, branch 'Branch belong', trans 'transaction'
from sql.Branches b left join sql.Transact t
on b.actnum = t.actnum
order by trans desc;
quit;
- Right join
Merge a(in=ina) b(in=inb);
If inb
proc sql;
select b.actnum, branch 'Branch belong', t.actnum, trans 'transaction'
from sql.Branches b right join sql.Transact t
on b.actnum = t.actnum
order by trans desc;
quit;
- Full join
Merge a(in=ina) b(in=inb);
If ina or inb
proc sql;
select b.actnum, branch '#Branch#belong', t.actnum, trans '#transaction#happened'
from sql.Branches b full join sql.Transact t
on b.actnum = t.actnum
order by trans desc;
quit;
SQLJoin操作:内连接、左连接、右连接和全连接示例
本文展示了SQL中的四种JOIN操作:内连接(Innerjoin)、左连接(Leftjoin)、右连接(Rightjoin)和全连接(Fulljoin)。通过具体的代码示例,解释了如何基于共同的actnum字段将sql.Branches和sql.Transactt两个表进行合并,从而获取不同类型的连接结果。
1870

被折叠的 条评论
为什么被折叠?



