Jump to content


Photo

Consulta Em Mais De Uma Tabela Mysql


  • Faça o login para participar
3 replies to this topic

#1 FaustiniJr

FaustiniJr

    Novato no fórum

  • Usuários
  • 11 posts
  • Sexo:Não informado

Posted 16/12/2010, 07:25

Pessoal,
estou fazendo trabalho de conclusao de curso, nele preciso fazer um consulta em que os dados estão em várias tabelas. As tabelas são:

'rotas' que possui as colunas 'parEstCod' (neste tenho que fazer um like) e 'rotaId'

'linhas' que possui as colunas 'rotaId' e 'linhaId' e 'linhaDest'

'tarifasRotas' que possui as colunas 'rotaId' e 'destId' e 'tarRotaId'

'agendaServ' que possui as colunas 'linhaId' e 'horaInicial'

'tempoParadas' que possui as colunas 'linhaId' e 'parEstCod' e 'parEstChegTemp'

Ou seja, com essas tabelas e colunas, através de um código de uma parada, eu preciso encontrar o próximo horário para aquela parada. Na consulta a tabela 'agendaServ', deveria dar o primeiro resultado (LIMIT 1) que seja maior ou igual a hora atual.

Após a consulta a tabela 'tempoParadas', deveria somar os tempos encontrados no resultado da consulta a tabela 'agendaServ' e 'tempoParadas'.

Eu deveria fazer a seguinte consulta:

na tabela rotas, pesquiso as rotaId onde parEstCod contém ibt071 (LIKE)

na tabela linhas, pesquiso as linhaId de acordo com o resultado tido pelo rotaId e onde linhaDest é centro e/ou ipatinga

na tabela tarifaRotas, pesquiso pelas tarRotaId de acordo com o resultado tido pelo rotaId e onde destId é igual a centro e/ou ipatinga

na tabela agendaServ, pesquiso pela horaInicial (LIMIT 1) que seja maior ou igual a hora atual de acordo com o resultado tido pela linhaID

na tabela tempoParadas, pesquiso a parEstChegTemp de acordo com o resultado tido pela linhaId e pelo código ibt071

após a consulta, faço a soma horaInicial+parEstChegTemp == 06:45:00 + 00:04:58 = resultCheg=06:49:58

tudo isso para exibir a mensagem: "próximo onibus: $servId para $linhaDest as $resultCheg (R$ $tarRotaId)"


Estava fazendo algo mais ou menos assim:
SELECT *
FROM `rotas`
 LEFT JOIN `radiogalaxia`.`linhas` ON `rotas`.`rotaId` = `linhas`.`linhaId` 
 LEFT JOIN `radiogalaxia`.`tarifaRotas` ON `rotas`.`rotaId` = `tarifaRotas`.`rotaId` 
WHERE ((`rotas`.`rotaId` WHERE `parEstCod` LIKE '%ibt071%') AND (`linhas`.`linhaId` WHERE `rotaId` = 1) AND (`tarifaRotas`.`tarRotaId` WHERE `rotaId` = 1))

Mas ao adicionar a consulta sql na minha página PHP, ao tentar exibir o resultado, simplesmente não aparece nada.

Alguém saberia me dizer o que estou fazendo de errado?

Grato

#2 André Manoel

André Manoel

    Doutor

  • Usuários
  • 996 posts
  • Sexo:Masculino
  • Localidade:Brasilia

Posted 16/12/2010, 14:23

Coloque o script de criação da tabela e o script com os inserts que vc tem...
Iniciando na Ajuda On line...

Posted Image Meu post lhe ajudou? Reputar/votar é uma das formas de agradecer.

#3 FaustiniJr

FaustiniJr

    Novato no fórum

  • Usuários
  • 11 posts
  • Sexo:Não informado

Posted 16/12/2010, 14:42


-- phpMyAdmin SQL Dump

-- version 3.3.3

-- http://www.phpmyadmin.net

--

-- Servidor: mysql05.kinghost.net

-- Tempo de Geração: Dez 16, 2010 as 03:40 PM

-- Versão do Servidor: 5.1.52

-- Versão do PHP: 5.2.9



SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";





/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;

/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8 */;



--

-- Banco de Dados: `radiogalaxia`

--



-- --------------------------------------------------------



--

-- Estrutura da tabela `agendaExce`

--



CREATE TABLE IF NOT EXISTS `agendaExce` (

  `agExceId` int(11) NOT NULL AUTO_INCREMENT,

  `servId` int(11) NOT NULL,

  `exceNome` varchar(100) NOT NULL,

  `segId` int(1) DEFAULT NULL,

  `terId` int(1) DEFAULT NULL,

  `quaId` int(1) DEFAULT NULL,

  `quiId` int(1) DEFAULT NULL,

  `sexId` int(1) DEFAULT NULL,

  `sabId` int(1) DEFAULT NULL,

  `domId` int(1) DEFAULT NULL,

  `hora` time NOT NULL,

  `exceTip` int(1) NOT NULL,

  PRIMARY KEY (`agExceId`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;



--

-- RELAÇÕES PARA A TABELA `agendaExce`:

--   `servId`

--       `linhas` -> `linhaId`

--



--

-- Extraindo dados da tabela `agendaExce`

--



INSERT INTO `agendaExce` (`agExceId`, `servId`, `exceNome`, `segId`, `terId`, `quaId`, `quiId`, `sexId`, `sabId`, `domId`, `hora`, `exceTip`) VALUES

(1, 3, 'sabado nao tem', NULL, NULL, NULL, NULL, NULL, 1, NULL, '06:10:00', 0),

(2, 3, 'sabado nao tem', 0, 0, 0, 0, 0, 1, 0, '06:20:00', 0),

(3, 3, 'sab nao tem', 0, 0, 0, 0, 0, 1, 0, '07:05:00', 0),

(4, 3, 'sabado nao tem', 0, 0, 0, 0, 0, 1, 0, '07:20:00', 0),

(5, 3, 'sab nao tem', 0, 0, 0, 0, 0, 1, 0, '07:40:00', 0),

(6, 3, 'sab nao tem', 0, 0, 0, 0, 0, 1, 0, '07:41:00', 0);



-- --------------------------------------------------------



--

-- Estrutura da tabela `agendaServ`

--



CREATE TABLE IF NOT EXISTS `agendaServ` (

  `agSrvId` int(11) NOT NULL AUTO_INCREMENT,

  `linhaId` int(11) NOT NULL,

  `rotaId` int(11) NOT NULL,

  `segId` int(1) DEFAULT NULL,

  `terId` int(1) DEFAULT NULL,

  `quaId` int(1) DEFAULT NULL,

  `quiId` int(1) DEFAULT NULL,

  `sexId` int(1) DEFAULT NULL,

  `sabId` int(1) DEFAULT NULL,

  `domId` int(1) DEFAULT NULL,

  `dataInicial` date NOT NULL,

  `dataFinal` date NOT NULL,

  `horaInicial` time NOT NULL,

  `horaFinal` time NOT NULL,

  PRIMARY KEY (`agSrvId`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;



--

-- RELAÇÕES PARA A TABELA `agendaServ`:

--   `linhaId`

--       `linhas` -> `linhaId`

--   `rotaId`

--       `rotas` -> `rotaId`

--



--

-- Extraindo dados da tabela `agendaServ`

--



INSERT INTO `agendaServ` (`agSrvId`, `linhaId`, `rotaId`, `segId`, `terId`, `quaId`, `quiId`, `sexId`, `sabId`, `domId`, `dataInicial`, `dataFinal`, `horaInicial`, `horaFinal`) VALUES

(1, 3, 2, 1, 1, 1, 1, 1, 1, 1, '2010-12-01', '2011-03-31', '05:00:00', '05:35:00'),

(2, 3, 2, 1, 1, 1, 1, 1, 1, 1, '2010-12-01', '2011-03-31', '05:30:00', '06:05:00'),

(3, 3, 2, 1, 1, 1, 1, 1, 1, 1, '2010-12-01', '2011-03-31', '06:10:00', '06:45:00'),

(4, 3, 2, 1, 1, 1, 1, 1, 1, 1, '2010-12-01', '2011-03-31', '06:20:00', '06:55:00'),

(5, 3, 2, 1, 1, 1, 1, 1, 1, 1, '2010-12-01', '2011-03-31', '06:30:00', '07:05:00'),

(6, 3, 2, 1, 1, 1, 1, 1, 1, 1, '2010-12-01', '2011-03-31', '06:45:00', '07:15:00'),

(7, 3, 2, 1, 1, 1, 1, 1, 1, 1, '2010-12-01', '2011-03-31', '07:05:00', '07:40:00'),

(8, 3, 2, 1, 1, 1, 1, 1, 1, 1, '2010-12-01', '2011-03-31', '07:20:00', '07:55:00'),

(9, 3, 2, 1, 1, 1, 1, 1, 1, 1, '2010-12-01', '2011-03-31', '07:40:00', '08:15:00'),

(10, 3, 2, 1, 1, 1, 1, 1, 1, 1, '2010-12-01', '2011-03-31', '07:41:00', '08:16:00'),

(11, 3, 2, 1, 1, 1, 1, 1, 1, 1, '2010-12-01', '2011-03-31', '08:00:00', '08:35:00');



-- --------------------------------------------------------



--

-- Estrutura da tabela `empresa`

--



CREATE TABLE IF NOT EXISTS `empresa` (

  `empId` int(11) NOT NULL AUTO_INCREMENT,

  `empNome` varchar(120) NOT NULL,

  `empUrl` varchar(120) DEFAULT NULL,

  `empTime` datetime DEFAULT NULL,

  `empEnd` varchar(500) NOT NULL,

  `empCEP` int(8) NOT NULL,

  `empTel` varchar(13) DEFAULT NULL,

  PRIMARY KEY (`empId`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;



--

-- Extraindo dados da tabela `empresa`

--



INSERT INTO `empresa` (`empId`, `empNome`, `empUrl`, `empTime`, `empEnd`, `empCEP`, `empTel`) VALUES

(1, 'AutoTrans', 'http://www.autotransnet.com.br', '0000-00-00 00:00:00', 'Av. Selim José Salles, 1408 - Ipatinga - MG', 35164213, '3138278265'),

(2, 'Univale Transportes', 'http://www.univale.com', '0000-00-00 00:00:00', 'Avenida Presidente Tancredo de Almeida Neves, 3741 - Coronel Fabriciano - MG', 35171302, '3138651600'),

(7, 'BH Trans', '', '0000-00-00 00:00:00', 'Rua ubá, 200, belo horizonte', 30100100, '3132259000'),

(8, 'phone', '', '0000-00-00 00:00:00', 'rua ibiete, 42 ', 31155000, '3185236425');



-- --------------------------------------------------------



--

-- Estrutura da tabela `endereco`

--



CREATE TABLE IF NOT EXISTS `endereco` (

  `endId` int(11) NOT NULL AUTO_INCREMENT,

  `tipoEnd` varchar(100) NOT NULL,

  `end` varchar(120) NOT NULL,

  `parEstDesc` varchar(10) NOT NULL,

  PRIMARY KEY (`endId`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;



--

-- Extraindo dados da tabela `endereco`

--





-- --------------------------------------------------------



--

-- Estrutura da tabela `frequencias`

--



CREATE TABLE IF NOT EXISTS `frequencias` (

  `linhaId` int(11) NOT NULL,

  `tempInicio` time NOT NULL,

  `tempFim` time NOT NULL,

  `tempDif` time NOT NULL,

  PRIMARY KEY (`linhaId`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1;



--

-- RELAÇÕES PARA A TABELA `frequencias`:

--   `linhaId`

--       `linhas` -> `linhaId`

--



--

-- Extraindo dados da tabela `frequencias`

--





-- --------------------------------------------------------



--

-- Estrutura da tabela `funcionarios`

--



CREATE TABLE IF NOT EXISTS `funcionarios` (

  `funcId` int(11) NOT NULL AUTO_INCREMENT,

  `funcNome` varchar(120) NOT NULL,

  `funcCPF` int(11) NOT NULL,

  `funcEnd` varchar(500) NOT NULL,

  `funcCargo` varchar(120) NOT NULL,

  `funcCNH` varchar(13) DEFAULT NULL,

  `funcSal` int(10) NOT NULL,

  PRIMARY KEY (`funcId`),

  UNIQUE KEY `funcCPF` (`funcCPF`,`funcCNH`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;



--

-- Extraindo dados da tabela `funcionarios`

--



INSERT INTO `funcionarios` (`funcId`, `funcNome`, `funcCPF`, `funcEnd`, `funcCargo`, `funcCNH`, `funcSal`) VALUES

(1, 'Francisco Pedro', 2147483647, 'Rua 1, 45 - iguaçu - ipatinga, mg', 'Motorista', '20010039210', 1300),

(2, 'Paulo Faustini Jr', 2147483647, 'rua manoel samora, 134 - bromelias - timóteo - mg', 'Supervisor de TI', '', 2615),

(3, 'José Geraldo do Nascimento', 2147483647, 'rua 13, 234 - timirim - timoteo - mg', 'Motorista', '21033249700', 900),

(4, 'Pedro Gonçalves da Costa', 1212398701, 'rua amanha, 987 - ap 101 - melo viana - coronel fabriciano - mg', 'Serviços Gerais', '', 715);



-- --------------------------------------------------------



--

-- Estrutura da tabela `linhas`

--



CREATE TABLE IF NOT EXISTS `linhas` (

  `linhaId` int(11) NOT NULL AUTO_INCREMENT,

  `servId` int(11) NOT NULL,

  `rotaId` int(11) NOT NULL,

  `linhaDest` varchar(100) NOT NULL,

  `linhaNome` varchar(100) NOT NULL,

  `dirId` int(1) DEFAULT NULL,

  `blocoLinhaId` int(11) NOT NULL,

  `tracadoDef` varchar(70) DEFAULT NULL,

  PRIMARY KEY (`linhaId`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;



--

-- RELAÇÕES PARA A TABELA `linhas`:

--   `rotaId`

--       `rotas` -> `rotaId`

--   `servId`

--       `agendaServ` -> `agSrvId`

--



--

-- Extraindo dados da tabela `linhas`

--



INSERT INTO `linhas` (`linhaId`, `servId`, `rotaId`, `linhaDest`, `linhaNome`, `dirId`, `blocoLinhaId`, `tracadoDef`) VALUES

(1, 1750, 3, 'ipatinga', 'ipatinga/timóteo', NULL, 0, NULL),

(2, 1751, 3, 'timóteo', 'ipatinga/timóteo', NULL, 0, NULL),

(3, 701, 2, 'centro', 'vila militar/centro', NULL, 0, NULL),

(4, 702, 2, 'vila militar', 'vila militar/centro', NULL, 0, NULL),

(5, 1020, 1, 'ipatinga', 'industrial/ipatinga', NULL, 0, NULL),

(6, 1022, 1, 'industrial', 'industrial/ipatinga', NULL, 0, NULL);



-- --------------------------------------------------------



--

-- Estrutura da tabela `paradas`

--



CREATE TABLE IF NOT EXISTS `paradas` (

  `parEstId` int(11) NOT NULL AUTO_INCREMENT,

  `parEstCod` varchar(6) NOT NULL,

  `parEstNome` varchar(120) NOT NULL,

  `parEstDesc` varchar(500) DEFAULT NULL,

  `parEstLat` int(11) NOT NULL,

  `parEstLon` int(11) NOT NULL,

  `zonaId` int(11) DEFAULT NULL,

  `parEstUrl` varchar(120) DEFAULT NULL,

  `locTip` int(1) NOT NULL,

  `estDef` int(1) NOT NULL,

  `parEmbTip` int(1) NOT NULL,

  `parDesTip` int(1) NOT NULL,

  PRIMARY KEY (`parEstId`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;



--

-- Extraindo dados da tabela `paradas`

--



INSERT INTO `paradas` (`parEstId`, `parEstCod`, `parEstNome`, `parEstDesc`, `parEstLat`, `parEstLon`, `zonaId`, `parEstUrl`, `locTip`, `estDef`, `parEmbTip`, `parDesTip`) VALUES

(1, 'ibt071', 'bethanea / unipac', 'em frente ao Bretas do Bethânea', 19263841, 42332161, 0, '', 0, 0, 1, 1),

(2, 'ifn00', 'centro / final', 'ao lado da Delegacia de Polícia Civil', 19285316, 42311091, 0, '', 0, 0, 1, 1),

(3, 'iig032', 'iguaçu / granville', 'em frente a Granville Peugeot', 19282987, 42323274, 0, '', 0, 0, 1, 1),

(4, 'ffn000', 'centro / final', 'ao lado da praça da estação', 19314477, 42372416, 0, '', 1, 0, 1, 1),

(5, 'fcb010', 'centro / biboca', 'em frente ao Biboca Calçados', 19312328, 42373692, 0, '', 0, 0, 1, 1),

(6, 'tfn000', 'centro / final', 'atrás da escola estadual antônio silva', 19321320, 42385852, 0, '', 1, 0, 1, 1),

(7, 'tcb007', 'centro / betel', 'em frente ao Betel', 19322307, 42385453, 0, '', 0, 0, 1, 1);



-- --------------------------------------------------------



--

-- Estrutura da tabela `rotas`

--



CREATE TABLE IF NOT EXISTS `rotas` (

  `rotaId` int(11) NOT NULL AUTO_INCREMENT,

  `empId` int(11) NOT NULL,

  `rotaPqNome` varchar(50) NOT NULL,

  `rotaNome` varchar(150) NOT NULL,

  `rotaDesc` varchar(500) DEFAULT NULL,

  `rotaTip` int(1) NOT NULL,

  `rotaUrl` varchar(120) DEFAULT NULL,

  `rotaCor` varchar(6) DEFAULT NULL,

  `rotaTxtCor` varchar(6) DEFAULT NULL,

  `parEstSeq` varchar(1000) NOT NULL,

  `parEstCod` varchar(500) NOT NULL,

  PRIMARY KEY (`rotaId`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;



--

-- RELAÇÕES PARA A TABELA `rotas`:

--   `empId`

--       `empresa` -> `empId`

--   `rotaId`

--       `linhas` -> `linhaId`

--



--

-- Extraindo dados da tabela `rotas`

--



INSERT INTO `rotas` (`rotaId`, `empId`, `rotaPqNome`, `rotaNome`, `rotaDesc`, `rotaTip`, `rotaUrl`, `rotaCor`, `rotaTxtCor`, `parEstSeq`, `parEstCod`) VALUES

(1, 2, 'indipa', 'industrial/ipatinga', 'industrial, vagalume, bethania, canaa, caçula, jrd panorama, veneza, centro', 1, NULL, NULL, NULL, 'industrial: av. lafaiete lopes, rua olimpio campos, rua gliceria de almeida, rodovia mh 232 / vagalume: av. jose raimundo / bethania: av. alberto giovanine / canaa: av. selim jose de sales, av. minas gerais / caçula: av. minas gerais / jrd panorama: av. jk / veneza: av. macapa / centro: rua uberlandia, rua diamantina, av. joao v pascoal, praça caratinga', 'iid001, iid003, iid005, iid232, ivg002, ibt071, ica010, ica003, icc012, ijp023, ivz010, ict040, ict050, ict070, ict000'),

(2, 1, 'vilacentro', 'vila militar/centro', 'vila militar, bethania, vila militar, bethania, canaa, canaazinho, caravelas, veneza 1, centro', 1, NULL, NULL, NULL, 'vila militar: av. jose barcelos / bethania: av. jose assis de vasconcelos / vila militar: rua tucuma, rua rebeca / bethania: av. alberto giovanine / canaa: av. selim jose de sales / canaazinho: rua macabeus, av. galileia / caravelas: av. getulio vargas / veneza 1: av. macapa / centro: rua uberlandia, rua diamantina, av. joao valentim pascoal', 'ivm008, ibt069, ivm010, ibt071, ica010, icz013, icv024, ivz010, ict040, ict050, ict070, ict000'),

(3, 2, 'ipatim', 'ipatinga/timoteo', 'Centro-Ipatinga, Novo Cruzeiro, Iguaçu-Ferroviários, Shopping do Vale-Horto, Caladinho-Bom Jesus, Todos os Santos, Núcleo Industrial, Santa Maria, Quitandinha-Vila dos Técnicos, Centro-Acesita, Funcionários, Timirim, Primavera, Primavera-São José, Centro-Timóteo, Ana Rita, Santa Cecília', 1, NULL, NULL, NULL, 'centro-ipatinga: Praça Caratinga, Av. João Valetim Pascoal / Novo Cruzeiro: Av. Claúdio Moura / Iguaçu-Ferroviários: Av. Pedro Linhares / Shopping do Vale-Horto: Av. Pedro Linhares / Caladinho-Bom Jesus: Av. Tancredo Neves / Todos os Santos: Av. Tancredo Neves / Núcleo Industrial: BR 381, Av. Emalto / Santa Maria: Rua 128 / Quitandinha-Vila dos Técnicos: Av. Senador Milton Campos - Centro-Acesita: Alameda 31 de Outubro, Rua 25 de Agosto, Rua 15 de Novembro / Funcionários: Av. JK / Timirim: Av. Monsenhor Rafael / Primavera: Rua 16 / Primavera-São José: Av. Acesita / Centro-Timóteo:  Praça 29 de Abril, Rua Padre Antônio de Araújo / Ana Rita: Av. Brasil, Rua Hungria, Rua Colômbia / Santa Cecília: Rua Chile, Choupana', 'ifn000, inc010, iif013, ish020, fcb012, fts002, fni011, tsm001, tqv026, tca001, tfc007, ttm002, tpr003, tsj006, tct001, tar010, tsc090');



-- --------------------------------------------------------



--

-- Estrutura da tabela `tarifaRotas`

--



CREATE TABLE IF NOT EXISTS `tarifaRotas` (

  `tarRotId` int(11) NOT NULL AUTO_INCREMENT,

  `tarifaId` int(11) NOT NULL,

  `rotaId` int(11) NOT NULL,

  `origemId` varchar(50) NOT NULL,

  `destId` varchar(50) NOT NULL,

  `tarRotaId` varchar(50) NOT NULL,

  PRIMARY KEY (`tarRotId`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;



--

-- RELAÇÕES PARA A TABELA `tarifaRotas`:

--   `rotaId`

--       `rotas` -> `rotaId`

--   `tarifaId`

--       `tarifas` -> `tarifaId`

--



--

-- Extraindo dados da tabela `tarifaRotas`

--



INSERT INTO `tarifaRotas` (`tarRotId`, `tarifaId`, `rotaId`, `origemId`, `destId`, `tarRotaId`) VALUES

(1, 7, 1, 'industrial', 'ipatinga', '2,00'),

(2, 7, 1, 'ipatinga', 'industrial', '2,00'),

(3, 8, 2, 'vila militar', 'centro', '2,20'),

(4, 8, 2, 'centro', 'vila militar', '2,20'),

(5, 9, 3, 'ipatinga', 'timóteo', '4,60'),

(6, 9, 3, 'timóteo', 'ipatinga', '4,60');



-- --------------------------------------------------------



--

-- Estrutura da tabela `tarifas`

--



CREATE TABLE IF NOT EXISTS `tarifas` (

  `tarifaId` int(11) NOT NULL AUTO_INCREMENT,

  `valor` varchar(10) NOT NULL,

  `moedaTip` varchar(2) NOT NULL,

  `pagaMetodo` varchar(30) NOT NULL,

  `transf` int(1) NOT NULL,

  `transfDur` int(1) DEFAULT NULL,

  PRIMARY KEY (`tarifaId`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;



--

-- Extraindo dados da tabela `tarifas`

--



INSERT INTO `tarifas` (`tarifaId`, `valor`, `moedaTip`, `pagaMetodo`, `transf`, `transfDur`) VALUES

(7, '2,00', 'R$', 'passagem e dinheiro', 0, NULL),

(8, '2,20', 'R$', 'cartão e dinheiro', 0, NULL),

(9, '4,60', 'R$', 'passagem e dinheiro', 0, NULL);



-- --------------------------------------------------------



--

-- Estrutura da tabela `tempoParadas`

--



CREATE TABLE IF NOT EXISTS `tempoParadas` (

  `tmpParId` int(11) NOT NULL AUTO_INCREMENT,

  `linhaId` int(11) NOT NULL,

  `parEstChegTemp` time NOT NULL,

  `parEstSaiTemp` time NOT NULL,

  `parEstCod` varchar(50) NOT NULL,

  `parEstOrd` int(2) NOT NULL,

  `parEstNome` varchar(50) NOT NULL,

  `distTemp` time NOT NULL,

  PRIMARY KEY (`tmpParId`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=31 ;



--

-- RELAÇÕES PARA A TABELA `tempoParadas`:

--   `linhaId`

--       `linhas` -> `linhaId`

--



--

-- Extraindo dados da tabela `tempoParadas`

--



INSERT INTO `tempoParadas` (`tmpParId`, `linhaId`, `parEstChegTemp`, `parEstSaiTemp`, `parEstCod`, `parEstOrd`, `parEstNome`, `distTemp`) VALUES

(2, 2, '00:00:00', '00:00:01', 'ifn000', 1, 'Centro / Ipatinga', '01:30:00'),

(3, 2, '00:03:45', '00:04:55', 'inc010', 2, 'Novo Cruzeiro / Renault', '01:30:00'),

(4, 2, '00:10:10', '00:10:57', 'iif013', 3, 'Ferroviários / Vale', '01:30:00'),

(5, 2, '00:17:03', '00:18:12', 'ish020', 4, 'Horto / Shopping', '01:30:00'),

(6, 2, '00:42:00', '00:42:46', 'fcb012', 5, 'Caladinho / Unileste', '01:30:00'),

(7, 2, '00:54:03', '00:54:58', 'fts002', 6, 'Todos os Santos / Guiauto', '01:30:00'),

(8, 2, '00:58:05', '00:59:06', 'fni011', 7, 'Núcleo Industrial / Villeforte', '01:30:00'),

(9, 2, '01:08:02', '01:08:53', 'tsm001', 8, 'Santa Maria / The Hall', '01:30:00'),

(10, 2, '01:12:10', '01:12:55', 'tqv026', 9, 'Vila dos Técnicos / CLC', '01:30:00'),

(11, 2, '01:16:01', '01:16:45', 'tca001', 10, 'Centro Acesita / Tia Eliane', '01:30:00'),

(12, 2, '01:18:19', '01:18:57', 'tfc007', 11, 'Funcionários / Premially', '01:30:00'),

(13, 2, '01:20:21', '01:20:50', 'ttm002', 12, 'Timirim / Unileste', '01:30:00'),

(14, 2, '01:22:00', '01:22:56', 'tpr003', 13, 'Primavera / Oikos', '01:30:00'),

(15, 2, '01:25:10', '01:25:40', 'tsj006', 14, 'Sao Jose / Bretas', '01:30:00'),

(16, 2, '01:26:02', '01:26:59', 'tct001', 15, 'Centro Timóteo / PMT', '01:30:00'),

(17, 2, '01:29:01', '01:29:49', 'tar010', 16, 'Ana Rita / Banco do Brasil', '01:30:00'),

(18, 2, '01:32:29', '01:33:45', 'tsc090', 17, 'Santa Cecilia / Choupana', '01:30:00'),

(19, 3, '00:00:00', '00:00:02', 'ivm008', 1, 'Vila Militar / Ipatinga', '00:35:00'),

(20, 3, '00:02:01', '00:03:05', 'ibt069', 2, 'Bethania / Ipatinga', '00:35:00'),

(21, 3, '00:03:59', '00:04:10', 'ivm010', 3, 'Vila Militar / Ipatinga', '00:35:00'),

(22, 3, '00:04:58', '00:06:01', 'ibt071', 4, 'Bethania / UNIPAC', '00:35:00'),

(23, 3, '00:07:01', '00:07:56', 'ica010', 5, 'Cannã / Ipatinga', '00:35:00'),

(24, 3, '00:09:02', '00:09:49', 'icz013', 6, 'Canaãzinho / Ipatinga', '00:35:00'),

(25, 3, '00:14:07', '00:15:10', 'icv024', 7, 'Caravelas / Ipatinga', '00:35:00'),

(26, 3, '00:23:58', '00:24:57', 'ivz010', 8, 'Veneza 1 / Ipatinga', '00:35:00'),

(27, 3, '00:28:02', '00:28:56', 'ict040', 9, 'Centro / Jovem Pan', '00:35:00'),

(28, 3, '00:29:05', '00:30:01', 'ict050', 10, 'Centro / Correios', '00:35:00'),

(29, 3, '00:32:12', '00:33:02', 'ict070', 11, 'Centro / Nativa', '00:35:00'),

(30, 3, '00:34:56', '00:35:30', 'ict000', 12, 'Centro / Ipatinga', '00:35:00');



-- --------------------------------------------------------



--

-- Estrutura da tabela `tracadoLinha`

--



CREATE TABLE IF NOT EXISTS `tracadoLinha` (

  `tracadoId` int(11) NOT NULL AUTO_INCREMENT,

  `tracadoPntLat` varchar(50) NOT NULL,

  `tracadoPntLon` varchar(50) NOT NULL,

  `tracadoPntSeq` varchar(50) NOT NULL,

  `tracadoDistPer` varchar(50) NOT NULL,

  PRIMARY KEY (`tracadoId`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;



--

-- Extraindo dados da tabela `tracadoLinha`

--





-- --------------------------------------------------------



--

-- Estrutura da tabela `transferencias`

--



CREATE TABLE IF NOT EXISTS `transferencias` (

  `transfId` int(11) NOT NULL AUTO_INCREMENT,

  `deParId` int(11) NOT NULL,

  `paraParId` int(11) NOT NULL,

  `transTip` int(11) NOT NULL,

  `transTempMin` time NOT NULL,

  PRIMARY KEY (`transfId`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;



--

-- Extraindo dados da tabela `transferencias`

--





-- --------------------------------------------------------



--

-- Estrutura da tabela `usuarios`

--



CREATE TABLE IF NOT EXISTS `usuarios` (

  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,

  `nome` varchar(100) NOT NULL,

  `usuario` varchar(50) NOT NULL,

  `senha` varchar(50) NOT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `usuario` (`usuario`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;



--

-- Extraindo dados da tabela `usuarios`

--



INSERT INTO `usuarios` (`id`, `nome`, `usuario`, `senha`) VALUES

(1, 'Paulo Faustini Jr', 'admin', 'admin'),

(2, 'BHTrans', 'BHT', 'admin'),

(3, 'UNIVALE', 'univaleadmin', 'admin');



-- --------------------------------------------------------



--

-- Estrutura da tabela `veiculo`

--



CREATE TABLE IF NOT EXISTS `veiculo` (

  `veicId` int(11) NOT NULL AUTO_INCREMENT,

  `veicNumber` int(11) NOT NULL,

  `veicPlaca` varchar(8) NOT NULL,

  `veicLimSent` int(11) NOT NULL,

  `veicLimPe` int(11) NOT NULL,

  `veicVagaEsp` int(1) NOT NULL,

  PRIMARY KEY (`veicId`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;



--

-- Extraindo dados da tabela `veiculo`

--



INSERT INTO `veiculo` (`veicId`, `veicNumber`, `veicPlaca`, `veicLimSent`, `veicLimPe`, `veicVagaEsp`) VALUES

(1, 16050, 'ghx1967', 44, 12, 1),

(2, 18400, 'ghx1862', 44, 12, 1),

(3, 11200, 'gli1239', 47, 12, 0),

(4, 9980, 'gga1741', 47, 12, 0),

(5, 16700, 'ghg0300', 44, 12, 0),

(6, 19909, 'gde1200', 44, 13, 0),

(7, 19999, 'gde1201', 44, 12, 0),

(10, 12345, 'abc1234', 45, 13, 0);





#4 jhrebuski

jhrebuski

    jhrhp

  • Usuários
  • 173 posts
  • Sexo:Não informado

Posted 19/12/2010, 12:53

Olha eu não entendi direito o que você precisa, mas fiz um sql aqui.
Teste ele no phpmyadmin, antes de colocal-lo no código.
E precisa de algumas alterações, colocar no select apenas os campos que você quer.

SELECT *
FROM
rotas r, linhas l, tarifaRotas tr, agendaServ a, tempoParadas tp
WHERE
r.parEstCod LIKE '%ibt071%' AND
l.rotaId = r.rotaId AND
tr.rotaId = r.rotaId AND
a.linhaId = l.linhaId AND
tp.linhaId = l.linhaId

Até mais.

Edição feita por: jhrebuski, 19/12/2010, 12:54.





1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq