Hola Mario: Si lo que vos queres es que te de totales por mes en el query deberias hacer algo como esto, agruparlo tambien por mes: select * from crosstab('select a.id_usuario,extract(month from a.fe_ingreso) as mes,sum(a.mo_orden)as valor from compras as a where extract(year from a.fe_ingreso)=2011 group by a.id_usuario,extract(month from a.fe_ingreso) order by 1'), as foo (Usuario varchar,Enero double precision,Febrero double precision,....,Diciembre double precision); Espero que sea lo que necesitas. Saludos Adriana
El lun, 28-02-2011 a las 15:10, Mario Soto Cordones escribió: > Hola lista, > > > > Tengo la siguiente sentencia: > > > > SELECT > > a.id_usuario, > > a.fe_ingreso, > > sum(a.mo_orden) as valor > > > > from compras.ordcab a > > where EXTRACT(year from a.fe_ingreso) = '2011' > > and a.id_usuario = 'MSOTO' > > GROUP BY > > a.id_usuario, > > a.fe_ingreso > > ORDER BY > > a.fe_ingreso > > > > y me entrega el siguiente resultado: > > > > id_usuario > > fe_ingreso > > valor > > MSOTO > > 2011-01-16 > > 492936 > > MSOTO > > 2011-01-17 > > 581556 > > MSOTO > > 2011-01-20 > > 583680 > > MSOTO > > 2011-01-22 > > 25000 > > MSOTO > > 2011-01-23 > > 1237415 > > MSOTO > > 2011-01-24 > > 1031500 > > MSOTO > > 2011-01-25 > > 100000 > > MSOTO > > 2011-01-26 > > 618849 > > MSOTO > > 2011-02-17 > > 177840 > > MSOTO > > 2011-02-18 > > 214320 > > MSOTO > > 2011-02-19 > > 1285920 > > MSOTO > > 2011-02-23 > > 4436424 > > > 12 row(s) > > Ahora bien cuando le aplico la crosstab: > > > > select * from crosstab('SELECT > > a.id_usuario, > > a.fe_ingreso, > > sum(a.mo_orden) as valor > > > > from compras.ordcab a > > where EXTRACT(year from a.fe_ingreso) = ''2011'' > > and a.id_usuario = ''MSOTO'' > > GROUP BY > > a.id_usuario, > > a.fe_ingreso > > ORDER BY > > a.fe_ingreso') > > as foo(usuario varchar, > > enero DOUBLE PRECISION, > > febrero DOUBLE PRECISION, > > marzo DOUBLE PRECISION, > > abril DOUBLE PRECISION, > > mayo DOUBLE PRECISION, > > junio DOUBLE PRECISION, > > julio DOUBLE PRECISION, > > agosto DOUBLE PRECISION, > > septiembre DOUBLE PRECISION, > > octubre DOUBLE PRECISION, > > noviembre DOUBLE PRECISION, > > diciembre DOUBLE PRECISION > > ); > > > > > > Me da éste resultado, el cual a simple vista es incorrecto: > > > > usuario > > enero > > febrero > > marzo > > abril > > mayo > > junio > > julio > > agosto > > septiembre > > octubre > > noviembre > > diciembre > > MSOTO > > 492936 > > 581556 > > 583680 > > 25000 > > 1237415 > > 1031500 > > 100000 > > 618849 > > 177840 > > 214320 > > 1285920 > > 4436424 > > > 1 row(s) > > Pero no entiendo porque… alguien me puede dar alguna pista > > > > Saludos y gracias > > > > > > - Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda@postgresql.org) Para cambiar tu suscripci�n: http://www.postgresql.org/mailpref/pgsql-es-ayuda