É o seguinte, preciso de uma consulta a qual envolve 4 tabelas (estou enviando a estrutura do meu Database para ajuda los a me ajudar hehe!
Então, preciso de uma consulta que faça o seguinte:

Mais ou menos isso, ou seja, pegue uma máquina (diario.cod_maquina) e filtre por diario.data e faça a somatória do tempo disponivel que é ligado por cod_turno na tabela diario.cod_turno e na tabela turnos.cod_turno. Aí as paradas é o seguinte, o que liga as tabelas lanc_paradas_op e lanc_paradas_mec é o diario.iddiario e lanc_paradas_op.diario_iddiario e lanc_paradas_mec.diario_iddiario.
Tendo isso, podemos criar um relatório tipo o da imagem a cima.
CREATE TABLE IF NOT EXISTS `diario` ( `iddiario` int(11) NOT NULL AUTO_INCREMENT, `cod_maquina` int(11) NOT NULL, `cod_fazenda` int(11) NOT NULL, `cod_talhao` int(11) NOT NULL, `cod_turno` int(11) NOT NULL, `cod_operador` int(11) NOT NULL, `data_2` date NOT NULL, `horimetro_inic` float NOT NULL, `horimetro_fim` float NOT NULL, `deslocamento` float DEFAULT NULL, `producao` int(11) DEFAULT NULL, `cod_operacao` int(11) NOT NULL, `refeicao` float DEFAULT NULL, `hextra` float DEFAULT NULL, `litros` float DEFAULT NULL, `horimetro_abas` float DEFAULT NULL, `hor_trab` float DEFAULT NULL, PRIMARY KEY (`iddiario`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=591; -- -------------------------------------------------------- CREATE TABLE IF NOT EXISTS `lanc_paradas_mec` ( `cod_parada_mec` int(11) NOT NULL AUTO_INCREMENT, `diario_iddiario` int(11) DEFAULT NULL, `desc_parada` varchar(255) CHARACTER SET utf8 DEFAULT NULL, `hora_inicio` float DEFAULT NULL, `hora_fim` float DEFAULT NULL, `data_3` date DEFAULT NULL, `paradamec` float DEFAULT NULL, PRIMARY KEY (`cod_parada_mec`), KEY `lanc_paradas_mec_FKIndex1` (`diario_iddiario`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=138; -- -------------------------------------------------------- CREATE TABLE IF NOT EXISTS `lanc_paradas_op` ( `cod_parada_op` int(11) NOT NULL AUTO_INCREMENT, `diario_iddiario` int(11) NOT NULL, `cod_parada` int(11) DEFAULT NULL, `hora_inic` float DEFAULT NULL, `hora_fim` float DEFAULT NULL, `data_3` date DEFAULT NULL, `paradaop` float DEFAULT NULL, PRIMARY KEY (`cod_parada_op`), KEY `lanc_paradas_op_FKIndex1` (`diario_iddiario`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=812; -- -------------------------------------------------------- CREATE TABLE IF NOT EXISTS `turnos` ( `cod_turno` int(11) NOT NULL AUTO_INCREMENT, `desc_turno` varchar(255) DEFAULT NULL, `horas` double DEFAULT NULL, PRIMARY KEY (`cod_turno`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11; -- --------------------------------------------------------
Edição feita por: Marschall, 21/10/2009, 07:46.