I have Payment Table
. This Payment Table has paymentCusId(It is Customer Id)
, paymentCredit
and paymentDebit
rows etc... How can I show, If Customer's Balance is less than 50 euros, I want to show how many customers balance less than 50 euros.
For example, 5 customers balance less than 50.
Can I solve this using sql query or php conditions ?
Code below:
$this->db->select('payment.paymentCusId, sum(paymentCredit) - sum(paymentDebit)');
$this->db->from('payment');
$this->db->where('sum(paymentCredit) - sum(paymentDebit) <', 50);
$query_debit = $this->db->get();
$number = $query_debit->num_rows();
echo $number;
This code not working well. What can I do to show the number of customers less than 50 euros?