我的问题是,我得到的是所有3个表中都存在的数据。但是我想显示其中任何一个表中都不存在的数据(即空格,或者如果该项在任何一个表中都不存在,则在该项上打印0)…我搜索了一下,发现可以通过fullouter连接来完成,但我不知道如何使用它。。控制器代码:
public function St_statement(){
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
if ($this->input->post('all'))
{
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->where('billdte >=', $newDate);
$this->db->where('billdte <=', $newDate2);
$this->db->select("Item");
$this->db->select("pgroup");
$this->db->select_sum("Stock");
$this->db->select_sum("quantity");
$this->db->select_sum("Qty");
$this->db->from('opstock');
$this->db->group_by("Item");
$this->db->order_by("pgroup",'asc');
$this->db->join('purchaseitem',' purchaseitem.Prdtname = opstock.Item','OUTER');
$this->db->join('salesitem','salesitem.Prdtname = purchaseitem.Prdtname','OUTER');
$this->db->join('itemmaster','itemmaster.itemname = purchaseitem.Prdtname','OUTER');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','OUTER');
$query = $this->db->get();
$data['query'] = $query;
$this->load->view('Inventory/St_Stmt', $data);
//$this->load->view('Inventory/St_Stmt1', $data);
}
if($this->input->post('selected'))
{
if($name = $this->input->post('businessType'))
{
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->where('billdte >=', $newDate);
$this->db->where('billdte <=', $newDate2);
$this->db->where('pgroup',$name);
$this->db->select("Item");
$this->db->select("pgroup");
$this->db->select_sum("Stock");
$this->db->select_sum("quantity");
$this->db->select_sum("Qty");
$this->db->from('opstock');
$this->db->group_by("Item");
$this->db->join('purchaseitem',' purchaseitem.Prdtname = opstock.Item','OUTER');
$this->db->join('salesitem','salesitem.Prdtname = purchaseitem.Prdtname','OUTER');
$this->db->join('itemmaster','itemmaster.itemname = purchaseitem.Prdtname','OUTER');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','OUTER');
$query = $this->db->get();
$data['query'] = $query;
$this->load->view('Inventory/St_Stmt', $data);
}
}
}
1条答案
按热度按时间gmol16391#
$query=“选择
Item
,pgroup
,总和(Stock
)作为Stock
,总和(quantity
)作为quantity
,总和(Qty
)作为Qty
从opstock
左连接purchaseitem
在purchaseitem
.Prdtname
=opstock
.Item
左连接salesitem
在salesitem
.Prdtname
=purchaseitem
.Prdtname
左连接itemmaster
在itemmaster
.itemname
=purchaseitem
.Prdtname
左连接pgroup
在pgroup
.pgroupid
=itemmaster
.catcode
哪里billdate
>='“$newdate.”和billdate
<='“$newdate2.”和billdte
>='“$newdate.”和billdte
<='“$newdate2.”分组依据Item
订货人pgroup
asc联合选择Item
,pgroup
,总和(Stock
)作为Stock
,总和(quantity
)作为quantity
,总和(Qty
)作为Qty
从opstock
右连接purchaseitem
在purchaseitem
.Prdtname
=opstock
.Item
左连接salesitem
在salesitem
.Prdtname
=purchaseitem
.Prdtname
左连接itemmaster
在itemmaster
.itemname
=purchaseitem
.Prdtname
左连接pgroup
在pgroup
.pgroupid
=itemmaster
.catcode
哪里billdate
>='“$newdate.”和billdate
<='“$newdate2.”和billdte
>='“$newdate.”和billdte
<='“$newdate2.”分组依据Item
订货人pgroup
asc选择Item
,pgroup
,总和(Stock
)作为Stock
,总和(quantity
)作为quantity
,总和(Qty
)作为Qty
从opstock
左连接purchaseitem
在purchaseitem
.Prdtname
=opstock
.Item
右连接salesitem
在salesitem
.Prdtname
=purchaseitem
.Prdtname
左连接itemmaster
在itemmaster
.itemname
=purchaseitem
.Prdtname
左连接pgroup
在pgroup
.pgroupid
=itemmaster
.catcode
哪里billdate
>='“$newdate.”和billdate
<='“$newdate2.”和billdte
>='“$newdate.”和billdte
<='“$newdate2.”分组依据Item
订货人pgroup
asc联合选择Item
,pgroup
,总和(Stock
)作为Stock
,总和(quantity
)作为quantity
,总和(Qty
)作为Qty
从opstock
左连接purchaseitem
在purchaseitem
.Prdtname
=opstock
.Item
左连接salesitem
在salesitem
.Prdtname
=purchaseitem
.Prdtname
右连接itemmaster
在itemmaster
.itemname
=purchaseitem
.Prdtname
左连接pgroup
在pgroup
.pgroupid
=itemmaster
.catcode
哪里billdate
>='“$newdate.”和billdate
<='“$newdate2.”和billdte
>='“$newdate.”和billdte
<='“$newdate2.”分组依据Item
订货人pgroup
asc“;$query=$this->db->query($query);