日期:2014-05-17 浏览次数:20668 次
with t1 as
(
select 1 c1,'张三' c2 from dual union all
select 2 c1,'李四' c2 from dual union all
select 3 c1,'王五' c2 from dual
),t2 as
(
select 1 c3,'语文' c4 from dual union all
select 2 c3,'数学' c4 from dual union all
select 3 c3,'英语' c4 from dual
),t3 as
(
select 1 c5,1 c6,1 c7,80 c8 from dual union all
select 2 c5,1 c6,2 c7,66 c8 from dual union all
select 3 c5,2 c6,1 c7,78 c8 from dual union all
select 4 c5,3 c6,3 c7,95 c8 from dual
)
select a2,a4
from
(select c1 a1,c2 a2,c3 a3 ,c4 a4 from t1,t2) a
left join
(select c1 b1 ,c3 b3,c8 b8
from t1,t2,t3
where c1 = c6 and c3 = c7) b
on a1 = b1 and a3 = b3
where b8 is null
a2 a4
--------------------------
1 王五 语文
2 李四 英语
3 张三 英语
4 王五 数学
5 李四 数学