Re: crosstab de tablefunc no da los datos deseados

From: Gabriel Colina <colina_movil(at)yahoo(dot)com>
To: Jaime Casanova <systemguards(at)gmail(dot)com>, Ignacio Ayala Leal <ignacioal_3(at)hotmail(dot)com>
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: crosstab de tablefunc no da los datos deseados
Date: 2007-02-23 10:49:59
Message-ID: 299910.2415.qm@web34708.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda


--- Jaime Casanova <systemguards(at)gmail(dot)com> escribió:

> On 2/22/07, Ignacio Ayala Leal
> <ignacioal_3(at)hotmail(dot)com> wrote:
> > CREATE OR REPLACE FUNCTION crosstab_reporte(text)
> RETURNS SETOF meses AS
> > '$libdir/tablefunc', 'crosstab' LANGUAGE 'c'
> STABLE STRICT;
> >
> > hago la consulta select * from
> crosstab_reporte('select cliente,mes,importe
> > from cte order by 1,2;')
> >
>
> como tu sabes el numero de columnas (categorias, en
> este caso meses)
> que van a haber puedes hacer la consulta asi para
> evitar usar
> crosstab:
>
> select cliente,
> sum(case mes when 1 then importe else 0
> end) as enero,
> sum(case mes when 2 then importe else 0
> end) as febrero,
> sum(case mes when 3 then importe else 0
> end) as marzo,
> sum(case mes when 4 then importe else 0
> end) as abril,
> sum(case mes when 5 then importe else 0
> end) as mayo,
> sum(case mes when 6 then importe else 0
> end) as junio,
> sum(case mes when 7 then importe else 0
> end) as julio,
> sum(case mes when 8 then importe else 0
> end) as agosto,
> sum(case mes when 9 then importe else 0
> end) as septiembre,
> sum(case mes when 10 then importe else 0
> end) as octubre,
> sum(case mes when 11 then importe else 0
> end) as noviembre,
> sum(case mes when 12 then importe else 0
> end) as diciembre
> from cte
> group by cliente
> order by cliente;
>
> --
> 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
>
> ---------------------------(fin del
> mensaje)---------------------------
> TIP 8: explain analyze es tu amigo
>

Estoy tratando un problema parecido, anteriormente
trate el problema como lo expresa Jaime y cuando sabes
el numero de columnas categoricas es lo mejor.

Ahora bien el problema que tengo yo es que la funcion
crosstab esta en lenguaje 'C' y solo tengo instalado
pglsql.

Como instalo el C. ? para que crosstab funcione.

Algo me estoy comiendo al instalar lenguajes.

Atte.
Gabriel Colina

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
Regístrate ya - http://correo.espanol.yahoo.com/

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Gabriel Colina 2007-02-23 11:05:50 Re: Modelo entidad relacion
Previous Message Gabriel Colina 2007-02-23 10:46:20 Re: postgreslq y ems manager