Это данные в моей таблице с именем rent
id date stud_id paid balance
18 10-2016 94 15000 15000
19 10-2016 94 10000 5000
20 10-2016 96 25000 5000
21 10-2016 96 5000 0
Я хочу получить последний вставленный баланс stud_id, но получаю первый.
public function rent_outstanding($hos, $dt)
{
$this->db->select('student_hostel.*,rent.balance,rent.paid');
$this->db->join('rent', 'rent.stud_id=student_hostel.id');
$this->db->where('status!=', 'G');
$this->db->where('status!=', 'R');
$this->db->where('hostel', $hos);
$this->db->where('rent.date', $dt);
$this->db->select_sum('paid');
$this->db->group_by('stud_id');
$query = $this->db->get('student_hostel');
return $query;
}
Моя таблица Student_hostel выглядит так
id first_name last_name stud_id admit_date hostel class room bed status
94 ss ff PHBH00094 01-10-2016 12 16 115 501A P
96 maltu uv PHBH00096 01-10-2016 12 16 115 501C p
получу такой результат
SI.No STUDENT ID NAME RENT PAID BALANCE
1 PHBH00094 Ss 30000 25000 15000
2 PHBH00096 Maltu 30000 30000 5000
Я хочу получить такой результат
SI.No STUDENT ID NAME RENT PAID BALANCE
1 PHBH00094 Ss 30000 25000 5000
2 PHBH00096 Maltu 30000 30000 0
Подробнее здесь: https://stackoverflow.com/questions/403 ... -to-also-f