2013-10-11 21 views
0

我认为这仅仅是一个语法问题,我就加入,但我想查询加入到现有的表如何选择和使用表上一次查询

select * 
from 
    (
    (select 'Source1' Source from Dual 
    union select 'Source2' from Dual 
    union select 'Source3' from Dual 
    union select 'Source4' from Dual 
    ) 
    cross join (
     select 'O' Status from Dual 
     union select 'C' from Dual 
    ) 
    cross join (
     SELECT 
     TO_DATE('09/30/2013','mm/dd/yyyy') - 1 + LEVEL dt 
     FROM dual 
     CONNECT BY 
     LEVEL <= (TO_DATE('10/05/2013','mm/dd/yyyy') 
      - TO_DATE('09/30/2013','mm/dd/yyyy')) + 1 
    ) 
) as x 
left join 
    (
    select myTable.mySource 
    from myTable 
) as y 
on y.err_sts_cd = x.Status 
+0

所以你的问题是...?你有错误吗? – twoleggedhorse

回答

0

您应该能够只是除去大部分分组...的括号

select * 
from 
    (select 'Source1' Source from Dual 
    union select 'Source2' from Dual 
    union select 'Source3' from Dual 
    union select 'Source4' from Dual 
    ) s 
    cross join (
     select 'O' Status from Dual 
     union select 'C' from Dual 
    ) x 
    cross join (
     SELECT 
     TO_DATE('09/30/2013','mm/dd/yyyy') - 1 + LEVEL dt 
     FROM dual 
     CONNECT BY 
     LEVEL <= (TO_DATE('10/05/2013','mm/dd/yyyy') 
      - TO_DATE('09/30/2013','mm/dd/yyyy')) + 1 
    ) d 
left join 
    myTable y 
on y.err_sts_cd = x.Status 
0

没有y.err_sts_cd

left join 
    (
    select myTable.mySource 
    from myTable 
) as y 
on y.err_sts_cd = x.Status 

你需要要么加入使用ÿ .mySource或实际从myTable中选择err_sts_cd,约束:

select myTable.mySource, myTable.err_sts_cd 
    from myTable