2016-05-03 27 views
-1

我正在PHP和MySQL建立一个车队管理系统,我有我的表中选择查询的问题,因为我想系统生产每日,每周和每月的报告,这里是我的表..Mysql的选择问题

create table vehicles(veh_id tinyint not null auto_increment, Reg_number varchar(10)not null, primary key(veh_id)); 

create table transport(trans_id int not null auto_increment, veh_id tinyint not null, source varchar(10)not null, destination varchar(10)not null del_date date not null, load varchar(10)not null, customer varchar(10), primary key(trans_id)); 

create table expenses(exp_id)int not null auto_increment, veh_id tinyint not null, del_date date not null, trans_id int not null, cess varchar(10), labour varchar(10), allowances varchar(10), misc varchar(10), primary key(exp_id)); 

现在,当我运行此查询我只从两行还没有得到结果我有一个包含在我的表中的值多少行......这是我的查询,,

SELECT vehicles.Reg_number 
      , transport.trans_id 
      , transport.del_num 
      , transport.veh_id 
      , transport.destination 
      , transport.source 
      , transport.load 
      , expenses.cess 
      , expenses.labour 
      , expenses.exp_id 
      , expenses.allowances 
      , expenses.fuel 
from vehicles 
inner join transport using(veh_id) 
inner join expenses using(trans_id) 
where expenses.trans_id=transport.trans_id and 
     vehicles.veh_id=transport.veh_id and 
     transport.del_date between '2016-04-27' and '2016-05-06'; 

回答

0

你可能在这里使用错误的连接类型。这是一个相当不错的表现的SQL JOINS Visual Representation of Joins 这里是一个好堆栈溢出话题 Stack Overflow Joins

+0

谢谢库尔特利德利,为响应在看你的建议,现在做这件事的方式。 –

+0

运气好吗?我会尝试一个左连接 –