0

我认为这对我来说只是 Join 的语法问题,但我正在尝试将查询加入现有表

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
4

2 回答 2

0

没有 y.err_sts_cd

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

您需要使用 y.mySource 加入或实际从 myTable 中选择 err_sts_cd,通常:

    select myTable.mySource, myTable.err_sts_cd
    from myTable
于 2013-10-11T15:01:18.880 回答
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
于 2013-10-11T14:25:10.213 回答