title: oracle subquery inside case
body: <p>Hi Im trying to fetch a row from a subquery where the subquery fecha is the same as the main query fecha</p>
  
  <p>The error is</p>
  
  <pre class="lang-sql prettyprint-override"><code>ORA-00904: "F"."HORA_INICIO": identificador no válido
  00904. 00000 -  "%s: invalid identifier"
  </code></pre>
  
  <p>Here is my code</p>
  
  <pre><code>SELECT F.FECHA,
         COUNT(DISTINCT(F.CODIGO_DEPORTE)) AS CONTEODEPORTES,
         C.CONTEO AS CONTEO,
         CASE 
           WHEN C.CONTEO IS NULL THEN MIN(F.HORA_INICIO)
           ELSE (SELECT *
                   FROM (SELECT (SELECT NOMBRE_DEPORTE
                                   FROM DEPORTES
                                   WHERE PP.CODIGO_DEPORTE=DEPORTES.CODIGO_DEPORTE) AS NOM
                           FROM PROGRAMACIONES PP 
                           WHERE TO_CHAR(FECHA_INICIO, 'YYYY-MM-DD HH24:MI:SS') = 
                                   TO_CHAR(TO_DATE(F.FECHA,'DAY, DD "de" MONTH "de" YYYY'),'YYYY-MM-DD')
                                     || ' ' || F.HORA_INICIO
                           ORDER BY NOM)
                   WHERE ROWNUM=1)
         END AS PRIMER_DEPORTE
    FROM FECHAS F
    FULL OUTER JOIN CONTEO C
      ON (F.FECHA=C.FECHA AND
          F.HORA_INICIO=C.HORA_INICIO)
    GROUP BY F.FECHA,C.CONTEO
    ORDER BY TO_DATE(F.FECHA,'DAY, DD "de" MONTH "de" YYYY')
  </code></pre>
  
  <p>My problem is when trying to use F.FECHA it does not found the main query</p>
  
  <p>Thanks</p>