sql oracle与null值的联合

时间:2012-11-26 05:59:13

标签: sql oracle

我对2个视图进行了查询,当它结合时

查看X

A    B    C

2    3

查看Y

A    B    C

     3    4

这是我在2个观点中的查询

select * from view X
UNION 
select * from view Y;

我的结果:

A    B    C

2    3   

     3    4

我想要的结果(2覆盖视图Y @属性A中的空值):

A    B    C

2    3   

2    3    4

我怎么能得到那个?

2 个答案:

答案 0 :(得分:2)

试试这个

select nvl(A, lag(A) over (order by rownum)), B, C from (
  select A, B, C from X
  union 
  select A, B, C from Y
)

sqlfiddle

答案 1 :(得分:0)

这是oracle中的一个答案

select * from 
(select x from tbl1
union 
select x from tbl2) t1
,
(select y from tbl1
union 
select y from tbl2) t2
,
(select z from tbl1
union 
select z from tbl2) t3
where t1.x is not null
order by t1.x desc nulls first;