Tengo la siguiente tabla :
Código PHP:
CREATE TABLE mer_mov (
mer_mov_id int(11) NOT NULL auto_increment,
mer_id int(11) NOT NULL,
mer_mov_tipo set('E','S') NOT NULL default 'E,S',
mer_mov_cant varchar(10) NOT NULL,
mer_mov_fecha timestamp NOT NULL default CURRENT_TIMESTAMP,
mer_mov_motivo text,
mer_mov_usuario varchar(80) default NULL,
PRIMARY KEY (mer_mov_id),
KEY mer_id (mer_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Código MySQL:
Ver original
$entradas = mysql_query("SELECT mer_id, mer_mov_tipo, SUM(mer_mov_cant) AS entra FROM mer_mov WHERE mer_id = ".$id." AND mer_mov_tipo = 'E' GROUP BY mer_mov_tipo", $cnx); $salidas = mysql_query("SELECT mer_id, mer_mov_tipo, SUM(mer_mov_cant) AS sale FROM mer_mov WHERE mer_id = ".$id." AND mer_mov_tipo = 'S' GROUP BY mer_mov_tipo", $cnx);
jeje no debe ser muy elegante creo, pero funciona hasta ahora :P
Ahora el problema es que quiero hacer un reporte (listar) con todos los productos, osea la pregunta es:
¿Como puedo dejar todo eso en una sola consulta?
Para que quede sumado todas las Entradas y sumado todas las Salidas por producto...
Gracias