关于oracle多表联合查询的语句如何写?
有三张表如下:A表bhnamesl1a102b203c30B表bhnamesl11a52b203c25C表bhnamesl2sl31a502b200通过查询想得到如下结果...
有三张表如下:
A表
bh name sl
1 a 10
2 b 20
3 c 30
B表
bh name sl1
1 a 5
2 b 20
3 c 25
C表
bh name sl2 sl3
1 a 5 0
2 b 20 0
通过查询想得到如下结果:
bh name sl sl1 sl2 sl3
1 a 10 5 5 0
2 b 20 20 20 0
3 c 30 25
请问oracle中该如何写这个语句? 展开
A表
bh name sl
1 a 10
2 b 20
3 c 30
B表
bh name sl1
1 a 5
2 b 20
3 c 25
C表
bh name sl2 sl3
1 a 5 0
2 b 20 0
通过查询想得到如下结果:
bh name sl sl1 sl2 sl3
1 a 10 5 5 0
2 b 20 20 20 0
3 c 30 25
请问oracle中该如何写这个语句? 展开
10个回答
展开全部
SELECT nvl(nvl(a.bh,b.bh),c.bh) bh,
nvl(nvl(a.name,b.name),c.name) name,
A.SL,B.SL1,C.SL2,C.SL3
FROM A
full join B on A.bh= B.bh
full join C on A.bh= C.bh
nvl(nvl(a.name,b.name),c.name) name,
A.SL,B.SL1,C.SL2,C.SL3
FROM A
full join B on A.bh= B.bh
full join C on A.bh= C.bh
追问
谢谢你!!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SELECT A.BH,A.NAME,A.SL,B.SL1,C.SL2,C.SL3
FROM A
FULL OUTER JOIN B
ON A.BH=B.BH
AND A.NAME=B.NAME
FULL OUTER JOIN C
ON A.BH=C.BH
AND A.NAME=C.NAME
FROM A
FULL OUTER JOIN B
ON A.BH=B.BH
AND A.NAME=B.NAME
FULL OUTER JOIN C
ON A.BH=C.BH
AND A.NAME=C.NAME
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select a.bn,a.name,a.sl,b.sl1,c.sl2,c.sl3 from a join b on a.bn=b.bn join c on a.bn=c.bn
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select a.bh,a.name,a.sl,b.sl1,c.sl2,c.sl3 from a left join b on a.name = b.name left join c on a.name = c.name order by a.name
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个才是真的能用
select A.bh, A.name , sl, sl1,sl2,sl3
from
select distinct bn from (
(select distinct bn from a
union
select distinct bn from b
union
select distinct bn from c))as aa
left join a on a,bh=aa.bh
left join B on A.bh= B.bh
left join C on A.bh= C.bh
select A.bh, A.name , sl, sl1,sl2,sl3
from
select distinct bn from (
(select distinct bn from a
union
select distinct bn from b
union
select distinct bn from c))as aa
left join a on a,bh=aa.bh
left join B on A.bh= B.bh
left join C on A.bh= C.bh
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询