Re: consulta Por mese y dias

From: "Jaime Casanova" <systemguards(at)gmail(dot)com>
To: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: consulta Por mese y dias
Date: 2006-06-04 03:16:13
Message-ID: c2d9e70e0606032016h3ade1da7jc6343c44b4792c69@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

On 6/1/06, Nicolas Sorich <nsorich(at)udec(dot)cl> wrote:
>
>
> Select agno,operador,sum(ene) ene,sum(feb) feb,sum(mar) mar,sum(abr) abr
> sum(may) may,sum(jun) jun,sum(jul) jul,
> Sum(ago) ago,sum(sep) sep,sum(Oct) Oct,sum(Nov) Nov,sum(dic) dic, sum(total)
> total from
> (
> Select substr(re_fecha,5,9) agno, em_rut Operador,
> Sum(decode(substr(re_fecha,0,2),'01',1,0)) Ene,
> Sum(decode(substr(re_fecha,0,2),'02',1,0)) Feb,
> Sum(decode(substr(re_fecha,0,2),'03',1,0)) Mar,
> Sum(decode(substr(re_fecha,0,2),'04',1,0)) Abr,
> Sum(decode(substr(re_fecha,0,2),'05',1,0)) May,
> Sum(decode(substr(re_fecha,0,2),'06',1,0)) Jun,
> Sum(decode(substr(re_fecha,0,2),'07',1,0)) Jul,
> Sum(decode(substr(re_fecha,0,2),'08',1,0)) Ago,
> Sum(decode(substr(re_fecha,0,2),'09',1,0)) Sep,
> Sum(decode(substr(re_fecha,0,2),'10',1,0)) Oct,
> Sum(decode(substr(re_fecha,0,2),'11',1,0)) Nov,
> Sum(decode(substr(re_fecha,0,2),'12',1,0)) Dic,
> Sum(decode(substr(re_fecha,0,2),'01',1,0)) +
> Sum(decode(substr(re_fecha,0,2),'02',1,0)) +
> Sum(decode(substr(re_fecha,0,2),'03',1,0)) +
> Sum(decode(substr(re_fecha,0,2),'04',1,0)) +
> Sum(decode(substr(re_fecha,0,2),'05',1,0)) +
> Sum(decode(substr(re_fecha,0,2),'06',1,0)) +
> Sum(decode(substr(re_fecha,0,2),'07',1,0)) +
> Sum(decode(substr(re_fecha,0,2),'08',1,0)) +
> Sum(decode(substr(re_fecha,0,2),'09',1,0)) +
> Sum(decode(substr(re_fecha,0,2),'10',1,0)) +
> Sum(decode(substr(re_fecha,0,2),'11',1,0)) +
> Sum(decode(substr(re_fecha,0,2),'12',1,0)) Total
> FROM reserva
> GROUP BY substr(re_fecha,5,9),em_rut
> )
> Group by agno,operador;

decode tiene un significado distinto que en oracle...
http://www.postgresql.org/docs/8.1/static/functions-string.html

deberias estar usando case o puedes escribir una funcion que use case
por ti algo como:

create or replace function decode(string, string, int, int) returns int as $$
select case when $1 = $2 then $3 else $4;
$$ language 'sql' immutable;

supongo que es seguro marcar esta funcion como immutable

--
Atentamente,
Jaime Casanova

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."
Richard Cook

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Jaime Casanova 2006-06-04 04:16:08 Re: cuando creo una tabla quiero añadir un campo int4 nombrado cflavia "al vuelo"
Previous Message Abdiel Bernal H. 2006-06-04 01:49:33 RE: unsuscribe