日期:2014-05-17  浏览次数:20781 次

求一SQL语句(使用Oracle)
要求: 
A:a,b,c,d四个字段, 
表中数据 
aa,aa,aa,aa 
bb,bb,bb,bb 
cc,cc,cc,cc 
dd,dd,dd,dd 
B:a,b,r 三个字段 
表中数据 
aa,aa,a 
bb,bb,b 
cc,cc,c 
dd,dd,b 
显示结果: 

aa,aa,aa,aa,a 
bb,bb,bb,bb,b 
cc,cc,cc,cc,c 
dd,dd,dd,dd,d

------解决方案--------------------
不知道你表达的意思....
不过下面的语句应该能达到你的效果......

select A.a,A.b,A.c,A.d,B.r from A FULL JOIN B ON A.a=B.a
------解决方案--------------------
A:a,b,c,d四个字段,
表中数据
aa,aa,aa,aa
bb,bb,bb,bb
cc,cc,cc,cc
dd,dd,dd,dd 
  
B:a,b,r 三个字段
表中数据
aa,aa,a
bb,bb,b
cc,cc,c
dd,dd,b 
  
显示结果:
aa,aa,aa,aa,a
bb,bb,bb,bb,b
cc,cc,cc,cc,c
dd,dd,dd,dd,d <---------d怎么来的?B表对应是b
------解决方案--------------------
SQL code

select ta.a,ta.b,ta.c,ta.d,tb.r from 
(
select 'aa' a,'aa' b,'aa' c,'aa' d from dual union all
select 'bb','bb','bb','bb' from dual union all
select 'cc','cc','cc','cc' from dual union all
select 'dd','dd','dd','dd' from dual 
) ta
left join (
select * from 
(
select 'aa' a,'aa' b,'a' r from dual union all
select 'bb','bb','b' from dual union all
select 'cc','cc','c' from dual union all
select 'dd','dd','d' from dual 
) ) tb on ta.a=tb.a and ta.b=tb.b

-------------------------------------
       A    B    C    D    R
1    aa    aa    aa    aa    a
2    bb    bb    bb    bb    b
3    cc    cc    cc    cc    c
4    dd    dd    dd    dd    d