1、需求:
(1)三张表A、B、C 三个表id相同,如果A表中的name在B表中的bname中显示aname值,否则显示空;如果C表中的addr在B表中的tel显示addr,否则显示空
2、实现方式
(1)用decode函数
select
a.id,a.name,b.bname,b.tel,c.addr ,
decode(a.name,b.bname,a.name,null) as aname,
decode(c.addr,b.tel,c.addr,null) as addr
from A a,B b,C c where a.id=b.bid and b.bid=c.cid and a.id=c.cid
效果图:
(2)用case....when....实现
select
a.id,a.name,b.bname,c.addr ,
(case when a.name in (select bname from b) then a.name
else '' end
)
from A a,B b,C c where a.id=b.bid and b.bid=c.cid and a.id=c.cid
效果图: