how can I use a CASE with an alias defined befor case? how can I use an alias like pop in a further case like in this example (Oracle database).

select  
   (select sum(ccs_pop) from rap4) as pop,
case 
    when pop+x=a+b+c then pop+x
end as sum1,
case 
    when pop+y=d+e+f then pop+y
end as sum2
from rap4


The ideea is that I need "pop" in a complex situation and I need "pop" in many sentences and I need to use an alias or something...
OK, I'll take the provided example, and modify it a bit:

select  
    (&lt;insanely complex expression&gt;) as pop,
    case 
        when pop is null then 'isnull'
    end
from rap4 ;


The above will of course produce an error because an alias defined in the SELECT list, cannot be used in another expression in the same SELECT list or the (same level) WHERE or GROUP BY clauses.

What you can do however is either duplicate the expression:

select  
    (&lt;insanely complex expression&gt;) as pop,
    case 
        when &lt;insanely complex expression&gt; is null then 'isnull'
    end
from rap4 ;


or use a derived table:

select
    pop,
    case 
        when pop is null then 'isnull'
    end
from 
    ( select  
          (&lt;insanely complex expression&gt;) as pop
      from rap4
    ) t ;


or use a common table expression (CTE):

with cte as
  ( select  
        (&lt;insanely complex expression&gt;) as pop
    from rap4
 )
select
    pop,
    case 
        when pop is null then 'isnull'
    end
from cte ;