title: Oracle: Select Min with Where Clause
body: <p>I am trying to run the following statement against an Oracle database and getting a missing expression message. I suspect the issue is because the SELECTs for MINOVERLAP and MAXOVERLAP don't recognise OVERLAPS as a table, but I am now stuck. I am running this query within a tool called Qlikview, so don't have the benefit of creating temporary tables, etc. It needs to be done as a single query if at possible.</p>
  
  <pre><code>SELECT UCR, TR,
  SELECT(MIN(OVERLAP_START_DT)
  FROM OVERLAPS
  WHERE OVERLAPS.UCR=UCR
  AND OVERLAPS.TR  &lt;=TR) AS MINOVERLAP
  SELECT(MAX(OVERLAP_END_DT)
  FROM OVERLAPS
  WHERE OVERLAPS.UCR=UCR
  AND OVERLAPS.TR  &lt;=TR) AS MAXOVERLAP
  FROM
    (SELECT DISTINCT REF_WORKFLOW.UCR,
      REF_WORKFLOW.TR,
      OVERLAP_START_DT,
      OVERLAP_END_DT
    FROM CDW.REF_WORKFLOW
    JOIN CDW.REF_WEL_PREV_TR_OVERLAP
    ON REF_WEL_PREV_TR_OVERLAP.WORKFLOW_SID=REF_WORKFLOW.WORKFLOW_SID
    JOIN CDW.REF_TRANS_PART_LINE
    ON REF_TRANS_PART_LINE.UCR       =REF_WORKFLOW.UCR
    AND REF_TRANS_PART_LINE.TR       =REF_WORKFLOW.TR
    AND REF_TRANS_PART_LINE.BUREAU_ID='SY'
    JOIN CDW.REF_WORKFLOW_EVENT
    ON REF_WORKFLOW_EVENT.TRANS_PART_LINE_SID            =REF_TRANS_PART_LINE.TRANS_PART_LINE_SID
    WHERE REF_WORKFLOW.BUREAU_ID                         = 'SY'
    AND REF_TRANS_PART_LINE.PARTICIPANT_TRANS_ROLE_CODE IN('AGREEMENT PARTY','LEAD')
    AND REF_WEL_PREV_TR_OVERLAP.OVERLAP_ELAPSED_DURATION &gt;0
    AND REF_WORKFLOW_EVENT.WORKFLOW_EVENT_DT            &gt;= TO_DATE('24/04/2015','DD/MM/YYYY')
    ) OVERLAPS;
  </code></pre>