2011-12-16 94 views
0

我想在Oracle 10g的数据库执行查询加入两个子查询,因为它遵循:外的子查询与组加入

SELECT * FROM(
select count(y), x from a group by y) t1 
full join 
(select count(z), x from b group by z) t2 
on (t1.x = t2.x) 

的问题是,输出显示x作为两个不同的列它如下:

y   z   x   x1   
------------------------------------------- 
    2   4   1   1   
    3   (null)  2   (null)  
    2   (null)  3   (null)  
    8   (null)  4   (null)  
    (null)  4   (null)  5   
    (null)  6   (null)  6 

有没有人可以帮助我?提前致谢!

+2

请出示什么样的结果,你希望/欲望。我猜你想要一个联盟,但我不能确定,直到我知道你实际需要什么结果。 – MatBailie 2011-12-16 13:11:33

回答

1

我怀疑你想要的是:

SELECT coalesce(t1.x, t2.x) x, t1.y, t2.z 
FROM (select count(y), x from a group by x) t1 
full join (select count(z), x from b group by x) t2 on (t1.x = t2.x)