0

这是我的全部查询

    SELECT   empmst.emp_id, empmst.emp_name,
         (SELECT RTRIM
                    (XMLAGG (XMLELEMENT (e, d || ',')).EXTRACT ('//text()').EXTRACT
                                                                   ('//text()'),
                     ','
                    )
            FROM (SELECT TO_DATE ('01-04-2012', 'dd-MM-yyyy') - 1
                         + ROWNUM AS d
                    FROM all_objects
                   WHERE TO_DATE ('01-04-2012', 'dd-MM-yyyy') - 1 + ROWNUM <=
                                          TO_DATE ('30-04-2012', 'dd-MM-yyyy')
                  MINUS
                  SELECT tsd.ts_date
                    FROM ts_dtl tsd
                   WHERE empmst.emp_id = tsd.emp_id
                     AND tsd.ts_date BETWEEN TO_DATE ('01-04-2012',
                                                      'dd-MM-yyyy'
                                                     )
                                         AND TO_DATE ('30-04-2012',
                                                      'dd-MM-yyyy'
                                                     ))) AS day11
    FROM emp_mst empmst
   WHERE TSD.EMP_ID=EMPMST.EMP_ID
ORDER BY empmst.emp_id

我想将外部查询的 EMPMST.EMP_ID 传递给内部查询,但内部查询在 where 子句中没有得到 EMPMST.EMP_ID。请告诉我如何将外部查询从表传递到内部查询。内部查询如下

    (SELECT RTRIM
            (XMLAGG (XMLELEMENT (e, d || ',')).EXTRACT ('//text()').EXTRACT
                                                                   ('//text()'),
             ','
            )
   FROM (SELECT TO_DATE ('01-04-2012', 'dd-MM-yyyy') - 1 + ROWNUM AS d
           FROM all_objects
          WHERE TO_DATE ('01-04-2012', 'dd-MM-yyyy') - 1 + ROWNUM <=
                                          TO_DATE ('30-04-2012', 'dd-MM-yyyy')
         MINUS
         SELECT tsd.ts_date
           FROM emp_mst empmst, ts_dtl tsd
          WHERE empmst.emp_id = tsd.emp_id
            AND ts_date BETWEEN TO_DATE ('01-04-2012', 'dd-MM-yyyy')
                            AND TO_DATE ('30-04-2012', 'dd-MM-yyyy')))

我想要 emp_name 和 emp_id 和 TS_date,其中 4 月的 TS_DTL 中不存在的 TS_DATE 表示 TS_DTL 表中不存在的 4 月的其余日子

4

1 回答 1

0

请在下面找到将实现相同的

SELECT EMPMST.EMP_ID,
       EMPMST.EMP_NAME,
       rtrim(xmlagg(xmlelement(e, b.d1 || ',')).extract('//text()')
         .extract('//text()'),
         ',') as day11
  from (SELECT TO_DATE('01-04-2012', 'dd-MM-yyyy') - 1 + rownum AS d1
      FROM all_objects
     WHERE TO_DATE('01-04-2012', 'dd-MM-yyyy') - 1 + rownum <=
           TO_DATE('30-04-2012', 'dd-MM-yyyy')) b,
       EMP_MST EMPMST
 WHERE EMPMST.EMAIL_ID IS NOT NULL
   AND EMPMST.DEPT IN ('Technical')
   AND EMPMST.EMP_STATUS_LKP_ID = 201
   AND b.d1 NOT IN
       (SELECT TSD.TS_DATE as d2
      FROM TS_DTL TSD
     WHERE TSD.TS_DATE BETWEEN TO_DATE('01-04-2012', 'dd-MM-yyyy') AND
           TO_DATE('30-04-2012', 'dd-MM-yyyy')
       AND TSD.EMP_ID = EMPMST.EMP_ID)
 ORDER BY EMPMST.EMP_ID
于 2012-04-18T07:47:50.297 回答