从多个表中选择时选择总和输出不正确的结果 - Codeigniter 3.x模型

时间:2017-06-12 16:41:57

标签: php mysql codeigniter

我的模型中有这个功能:

public function lanlordEarnYear()
{
$this->db->select('l.*, p.pName, u.uName, SUM(ci.amount) AS totAmntYear, SUM(pay.amount) AS landPayYear, t.unitId');
$this->db->from('landlords l, properties p, units u, cashIn ci, tenants t, landlord_payment pay');
$this->db->where('pay.landlordId=l.id AND ci.tenantId=t.id AND t.unitId=u.id AND u.propertyId=p.id AND p.landlordId=l.id AND STR_TO_DATE(ci.registeredTime, "%Y")=STR_TO_DATE(CURDATE(), "%Y")');
$this->db->distinct();
$this->db->group_by('l.id');
$query = $this->db->get();
return $query->result_array();
}

关联的表格如下:

cashIn table:

cashIn table

房东表:

landlords table

0 个答案:

没有答案