slect t1.stu_id ,t1.lb,t1.jel,t2.je2
from t1,t2
where T1.STU_ID=T2.STU_ID(+)
union
(slect t2.stu_id ,t2.lb,t1.jel,t2.je2
from t1,t2
where T1.STU_ID(+)=T2.STU_ID )
from t1,t2
where T1.STU_ID=T2.STU_ID(+)
union
(slect t2.stu_id ,t2.lb,t1.jel,t2.je2
from t1,t2
where T1.STU_ID(+)=T2.STU_ID )
from t1,t2
where T1.STU_ID=T2.STU_ID and t1.lb = t2.lb(+)
union
(slect t1.stu_id ,t1.lb,t1.jel,t2.je2
from t1,t2
where T1.STU_ID=T2.STU_ID and t1.lb(+) = t2.lb )
T1的数据:
'01','01',123
'01','02',100
'02','02',100
T2的数据:
'01','01',54
'02',null,null
我想要下面的结果
STU_ID LB JE1 JE2
01 01 123 54
01 02 100
02 02 100
按照 lizhaogui() 的方法,会得到下面的结果
STU_ID LB JE1 JE2
01 01 123 54
01 02 100 54
02 02 100 null
02 null 100 null
from t1 left join t2
on t1.stu_id = t2.stu_id and t1.lb = t2.lb;STU_ID LB JE1 JE2
---------- ---------- --------- ---------
01 01 123 54
01 02 100
02 02 100 Executed in 0.031 secondsSQL>
select t1.stu_id,t1.lb,je1,je2
from t1 left join t2
on t1.stu_id = t2.stu_id and t1.lb = t2.lb
union
(select t2.stu_id,t2.lb,je1,je2
from t1 right join t2
on t1.stu_id = t2.stu_id and t1.lb = t2.lb;
)
lee_billiy(思思 )的试试看吧
T2:表示的是实际缴费金额;实际应用的逻辑中,T2(stu_id,lb)应该是T1(sdu_id,lb)的子集,楼主以为然否?所以,
我写的SQL语句中没有右连接。
from T1 a,T2 b
where a.stu_id=b.stu_id(+) and a.lb=b.lb(+)