Re: crosstab de tablefunc no da los datos deseados

From: "Ignacio Ayala Leal" <ignacioal_3(at)hotmail(dot)com>
To: colina_movil(at)yahoo(dot)com
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: crosstab de tablefunc no da los datos deseados
Date: 2007-02-24 01:51:55
Message-ID: BAY116-F6C248AAA6F7ADD14BF910CA8D0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda


Gracias por tu ayuda Gabriel

>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: [pgsql-es-ayuda] crosstab de tablefunc no da los datos
>deseados
>Date: Fri, 23 Feb 2007 04:49:59 -0600 (CST)
>
>
>--- 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/

_________________________________________________________________
Windows Live Spaces en Prodigy/MSN Spaces: Crea tu propio espacio.
http://spaces.live.com

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2007-02-24 02:01:55 Re: crosstab de tablefunc no da los datos deseados
Previous Message Ignacio Ayala Leal 2007-02-24 01:47:31 Re: crosstab de tablefunc no da los datos deseados