Re: Case sobre alias

From: Sebastian Webber <sebastian(at)swebber(dot)me>
To: douglas(dot)rauber(at)gmail(dot)com
Cc: pgsql-pt-geral(at)lists(dot)postgresql(dot)org
Subject: Re: Case sobre alias
Date: 2018-10-02 18:33:41
Message-ID: CACV2tSzXiN6WYNrBaeLEunnLwaUbgZHu8EWG=DP4-TG6zYL6Yw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-pt-geral

Oi Douglas, tudo bem?

Em ter, 2 de out de 2018 às 15:29, Douglas <douglas(dot)rauber(at)gmail(dot)com>
escreveu:

> Boa tarde!
>
> Eu gostaria de fazer um query assim:
>
> select
> case tab.colunaA
> when 'A' then 'Ok'
> when 'B' then 'Ok'
> when 'C' then 'Ok'
> when 'D' then 'Ok'
> when 'E' then 'Err'
> when 'F' then 'Err'
> when 'G' then 'Err'
> end as resultadoA,
> case resultadoA when 'Err' then 'Problemas' end as complemento
> from tab
>
> Mas recebo o retorno column "resultadoA" does not exist.
>

Isso só vai funcionar se voce criar essas colunas dentro de um subselect.
por exemplo:

WITH meus_campos AS (

select
case tab.colunaA
when 'A' then 'Ok'
when 'B' then 'Ok'
when 'C' then 'Ok'
when 'D' then 'Ok'
when 'E' then 'Err'
when 'F' then 'Err'
when 'G' then 'Err'
end as resultadoA
from tab

)
SELECT case resultadoA when 'Err' then 'Problemas' end as complemento
from meus_campos ;

> Como posso fazer para usar o resultado da coluna nomeada?
>
> Obrigado.
>
> Douglas
>

[]'s

--
Sebastian Webber
Chegou a ver o meu blog <http://swebber.me>? Dá uma olhada no que eu ando
aprontando: http://swebber.me

In response to

Browse pgsql-pt-geral by date

  From Date Subject
Next Message Vinicius Santos 2018-10-04 15:09:17 Descobrir arquiterura dos arquivoz
Previous Message Douglas 2018-10-02 18:29:30 Case sobre alias