Ver Mensaje Individual
  #5 (permalink)  
Antiguo 25/02/2013, 07:27
tumbero_x
 
Fecha de Ingreso: octubre-2010
Ubicación: Buenos Aires
Mensajes: 557
Antigüedad: 13 años, 7 meses
Puntos: 4
Respuesta: Problemas Con GROUP BY

OK gracias nuevamente
con respecto a a LEFT JOIN es porque en la tabla prod_bundle puede no existir el registro
que busco y tengo entendido que si hago INNER JOIN y no lo encuentra, tampoco me va a traer los registros de la tabla presuestos
pongo la consulta completa y la estructura
Código MySQL:
Ver original
  1. SELECT P.*,GROUP_CONCAT(A.presu_artiid)AS arti_id,
  2.                                         GROUP_CONCAT(B.prodbun_artiid)AS bundlearti_id,
  3.                                         GROUP_CONCAT(B.prodbun_cantidad)AS bundle_cantidad,
  4.                                    
  5.                                         B.prodbun_tipo,B.prodbun_numero,B.prodbun_id
  6.                                        
  7.                                       FROM presupuestos P
  8.                                      
  9.                                       INNER JOIN presupuestos2 A ON P.presu_id=A.presu2_id
  10.                                       LEFT JOIN prod_bundle B ON P.presu_id=B.prodbun_numero AND B.prodbun_tipo=0 AND A.presu_artiid=B.prodbun_id
  11.                                      
  12.                                            WHERE  P.presu_eliminado=0  AND P.presu_id =1
  13.                                            GROUP BY A.presu2_id,B.prodbun_id";
Código MySQL:
Ver original
  1. CREATE TABLE `presupuestos` (
  2.   `presu_id` int(11) NOT NULL auto_increment,
  3.   `presu_clienteid` int(11) NOT NULL,
  4.   `presu_lista` int(11) NOT NULL,
  5.   `presu_tipo` int(11) NOT NULL,
  6.   `presu_moneda` int(2) NOT NULL,
  7.   `presu_vendedor` int(11) NOT NULL,
  8.   `presu_usuario` varchar(100) NOT NULL,
  9.   `presu_suc` varchar(10) NOT NULL,
  10.   `presu_monecoti` int(11) NOT NULL,
  11.   `presu_coti` decimal(6,4) NOT NULL,
  12.   `presu_fecha` date NOT NULL,
  13.   `presu_fecharece` date NOT NULL,
  14.   `presu_hora` time NOT NULL,
  15.   `presu_eliminado` int(2) NOT NULL,
  16.   `presu_pedido` int(11) NOT NULL,
  17.   `presu_obser` text NOT NULL,
  18.   `presu_envio` int(11) NOT NULL,
  19.   `presu_envioprecio` decimal(15,4) NOT NULL,
  20.   `presu_modiven` varchar(100) NOT NULL,
  21.   `presu_modifecha` date NOT NULL,
  22.   `presu_modihora` time NOT NULL,
  23.   `presu_descuento` int(11) NOT NULL,
  24.   `presu_pordescuento` decimal(7,4) NOT NULL,
  25.   `presu_finaldescuento` decimal(15,4) NOT NULL,
  26.   `presu_eliusuario` varchar(100) NOT NULL,
  27.   `presu_elifecha` date NOT NULL,
  28.   `presu_elihora` time NOT NULL,
  29.   `presu_total` decimal(15,4) NOT NULL,
  30.   `presu_validez` int(11) NOT NULL,
  31.   `presu_tarjeta` text NOT NULL,
  32.   PRIMARY KEY  (`presu_id`)
  33.  
  34.  
  35. INSERT INTO `presupuestos` VALUES (1, 1, 2, 11, 6, 1, '6', '001', 7, 5.0600, '2013-02-24', '2013-02-24', '09:50:00', 0, 0, '', 1, 0.0000, '0', '0000-00-00', '00:00:00', 1, 10.0000, 192.0913, '0', '0000-00-00', '00:00:00', 1728.8213, 180, '');
Código MySQL:
Ver original
  1. CREATE TABLE `presupuestos2` (
  2.   `presu2_id` int(11) NOT NULL,
  3.   `presu_artiid` int(11) NOT NULL,
  4.   `presu_cantidad` int(11) NOT NULL,
  5.   `presu_porcentaje` decimal(15,4) NOT NULL,
  6.   `presu_pororiginal` decimal(15,4) NOT NULL,
  7.   `presu_precio` decimal(15,4) NOT NULL,
  8.   `presu_tipoiva` int(11) NOT NULL,
  9.   `presu_ivadetalle` varchar(10) NOT NULL,
  10.   `presu_iva` decimal(15,4) NOT NULL,
  11.   `presu_subtotal` decimal(15,4) NOT NULL,
  12.   `presu_bundle` int(1) NOT NULL,
  13.   `presu_manual` int(1) NOT NULL,
  14.   KEY `presu2_id` (`presu2_id`)
  15.  
  16.  
  17.  
  18. INSERT INTO `presupuestos2` VALUES (1, 5, 1, 26.0000, 40.0000, 15.2460, 1, '21.0000', 2.6460, 12.6000, 0, 0);
  19. INSERT INTO `presupuestos2` VALUES (1, 7, 10, 34.9999, 49.9999, 113.2238, 3, '10.5000', 10.7588, 1024.6496, 0, 0);
  20. INSERT INTO `presupuestos2` VALUES (1, 49, 1, 62.0000, 80.0000, 446.3375, 1, '21.0000', 77.4635, 368.8740, 1, 0);
  21. INSERT INTO `presupuestos2` VALUES (1, 1361710188, 10, 11.5702, 23.9669, 13.5000, 1, '21.0000', 2.3430, 111.5702, 0, 1);
Código MySQL:
Ver original
  1. CREATE TABLE `prod_bundle` (
  2.   `prodbun_tipo` int(1) NOT NULL,
  3.   `prodbun_numero` int(11) NOT NULL,
  4.   `prodbun_id` int(11) NOT NULL,
  5.   `prodbun_artiid` int(11) NOT NULL,
  6.   `prodbun_cantidad` int(11) NOT NULL,
  7.   KEY `presu3_id` (`prodbun_numero`),
  8.   KEY `presubundle_id` (`prodbun_id`)
  9.  
  10.  
  11. INSERT INTO `prod_bundle` VALUES (0, 1, 49, 5, 1);
  12. INSERT INTO `prod_bundle` VALUES (0, 1, 49, 7, 2);
GRACIAS!!!