我正在构建一个php和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 :(得分:0)
您可能在这里使用了错误的联接类型。这是SQL中JOINS的一个很好的表示 Visual Representation of Joins 这是一个很好的堆栈溢出主题 Stack Overflow Joins