我的模型中有这个功能:
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:
房东表: