porque no me funciona la clausula GROUP BY

1,120 views
Skip to first unread message

DIEGO A. CALLEGARI

unread,
Jan 11, 2012, 2:13:25 PM1/11/12
to publice...@googlegroups.com

Estimados.

 

                        Genero siguiente consulta, y me dice que la clausula GROUP BY falta o no es valida…

 

Select CRS_TBL_CAB_FACTURA.Comp,CRS_TBL_CAB_FACTURA.TIPO,CRS_TBL_CAB_FACTURA.FECHA,CRS_TBL_CAB_FACTURA.VTO,CRS_TBL_CAB_FACTURA.NUMERO,;

CRS_TBL_CAB_FACTURA.CODIGO_CLIENTE,CRS_TBL_CAB_FACTURA.VENDEDOR,CRS_TBL_CAB_FACTURA.CLIENTE,;

      IIF( Inlist(Comp,"FV","DI","CH","IN","RP"),SALDO,-SALDO) As SALDO,;

      IIF( Inlist(Comp,"FV","DI","CH","IN","RP"),IMPORTE,-IMPORTE) As IMPORTE;

      FROM CRS_TBL_CAB_FACTURA;

            where exist(select codigo FROM crs_clientes);

            ORDER By  CRS_TBL_CAB_FACTURA.CLIENTE,CRS_TBL_CAB_FACTURA.FECHA;

            GROUP BY CRS_TBL_CAB_FACTURA.CLIENTE;

            into Cursor Resumen

 

 

que estoy haciendo mal?

 

Diego A. Callegari

 

Yvan Carranza

unread,
Jan 11, 2012, 2:18:15 PM1/11/12
to publice...@googlegroups.com
pq lo que los campos que  pones en el select y no acumulas. tienes que ponerlo en el group by

Lewis López

unread,
Jan 11, 2012, 2:21:13 PM1/11/12
to publice...@googlegroups.com
Esto se da cuando usas vfp 9, ya que para una clausula GROUP BY se debe agrupar todas la columnas de la tabla.

contrarestar esto usa esto.

antes de la consulta.
SET ENGINEBEHAVIOR 70
tu consulta 

SET ENGINEBEHAVIOR 90 

saludos.

SOLUCIONES PC & REDES
Desarrollo de Software a la medida
Diseño de planos Arquitectónicos
Venta, reparación y mantenimiento de Computadores.
Lewis Oswaldo López Gómez .
Teg. En obras Civiles.
Analista y Programador de sistemas.
Cel: 311 665 0342
Correo:
Córdoba-Colombia




From: d_cal...@aceroschubut.com.ar
To: publice...@googlegroups.com
Subject: [vfp] porque no me funciona la clausula GROUP BY
Date: Wed, 11 Jan 2012 16:13:25 -0300

Miguel Canchas

unread,
Jan 11, 2012, 2:23:48 PM1/11/12
to publice...@googlegroups.com

Select CRS_TBL_CAB_FACTURA.Comp,CRS_TBL_CAB_FACTURA.TIPO,CRS_TBL_CAB_FACTURA.FECHA,CRS_TBL_CAB_FACTURA.VTO,CRS_TBL_CAB_FACTURA.NUMERO,;

CRS_TBL_CAB_FACTURA.CODIGO_CLIENTE,CRS_TBL_CAB_FACTURA.VENDEDOR,CRS_TBL_CAB_FACTURA.CLIENTE,;

      IIF( Inlist(Comp,"FV","DI","CH","IN","RP"),SALDO,-SALDO) As SALDO,;

      IIF( Inlist(Comp,"FV","DI","CH","IN","RP"),IMPORTE,-IMPORTE) As IMPORTE;

      FROM CRS_TBL_CAB_FACTURA;

            where exist(select codigo FROM crs_clientes);

            ORDER By  CRS_TBL_CAB_FACTURA.CLIENTE,CRS_TBL_CAB_FACTURA.FECHA;

            into Cursor Resumen

 

El GROUP BY es generalmente cuando hagas cálculos de SUMA, y en el GROUP BY tienen que ir todos los campos que no participan en el calculo, por ejemplo :

 

 

Select CRS_TBL_CAB_FACTURA.Comp,CRS_TBL_CAB_FACTURA.TIPO,CRS_TBL_CAB_FACTURA.FECHA,CRS_TBL_CAB_FACTURA.VTO,CRS_TBL_CAB_FACTURA.NUMERO,;

CRS_TBL_CAB_FACTURA.CODIGO_CLIENTE,CRS_TBL_CAB_FACTURA.VENDEDOR,CRS_TBL_CAB_FACTURA.CLIENTE,;

      SUM(IIF( Inlist(Comp,"FV","DI","CH","IN","RP"),SALDO,-SALDO)) As SALDO,;

      SUM(IIF( Inlist(Comp,"FV","DI","CH","IN","RP"),IMPORTE,-IMPORTE)) As IMPORTE;

      FROM CRS_TBL_CAB_FACTURA;

            where exist(select codigo FROM crs_clientes);

            ORDER By  CRS_TBL_CAB_FACTURA.CLIENTE,CRS_TBL_CAB_FACTURA.FECHA;

            GROUP BY CRS_TBL_CAB_FACTURA.Comp,CRS_TBL_CAB_FACTURA.TIPO,CRS_TBL_CAB_FACTURA.FECHA,CRS_TBL_CAB_FACTURA.VTO,CRS_TBL_CAB_FACTURA.NUMERO,;

CRS_TBL_CAB_FACTURA.CODIGO_CLIENTE,CRS_TBL_CAB_FACTURA.VENDEDOR,CRS_TBL_CAB_FACTURA.CLIENTE

            into Cursor Resumen

 

 

 

MK

DIEGO A. CALLEGARI

unread,
Jan 11, 2012, 2:45:10 PM1/11/12
to publice...@googlegroups.com

Gracias a todos, funciono la solucion de Lewis

 

 
Diego A. Callegari


Walter R. Ojeda Valiente

unread,
Jan 11, 2012, 6:28:22 PM1/11/12
to publice...@googlegroups.com
En el GROUP BY debes colocar TODAS LAS COLUMNAS que no sean calculadas (es decir, que no usen las funciones SUM(), AVG(), etc.)

Saludos.

Walter.




From: d_cal...@aceroschubut.com.ar
To: publice...@googlegroups.com
Subject: [vfp] porque no me funciona la clausula GROUP BY
Date: Wed, 11 Jan 2012 16:13:25 -0300

Daniel Sánchez

unread,
Jan 20, 2012, 8:44:16 PM1/20/12
to publice...@googlegroups.com
Mas que cambiar el SET ENGINEBEHAVIOR entre 70/80 te recomendaria que uses la correcta, ya que si migras tus consultas a una BD externa como SQLServer, MySQL, Firebird u otro te dara error si usas la consulta tal como la tienes, así que es mejor usar la manera estandar o correcta, ten encuenta que el VFP no es que considere correcto, si no que el completa en el group by los demás campos deduciendo que también debería estar, lo que con otro motor de BD no te lo resolvería si no te votaría error.

Saludos

--
Daniel Sánchez Escobar
Investigación y Desarrollo
Reset Software & Sistemas
Móvil +051-949398047
Trujillo - Perú
Reply all
Reply to author
Forward
0 new messages