Что было бы не так с моим запросом активной записи Функция суммы работает нормально, но детали подсчета возвращают количество всех записей. < /p>
$this->db->select(
'
t1.account_balance,
t2.CustomerName AS customer,
t2.CustomerId,
SUM(IF(t3.Bargain="Sale",t3.TotalAmount,0)) AS total_sale,
SUM(IF(t3.Bargain="Purchase",t3.TotalAmount,0)) AS total_buy,
COUNT(IF(t3.Bargain="Sale",t3.Bargain,0)) AS count_sale,
COUNT(IF(t3.Bargain="Purchase",t3.Bargain,0)) AS count_buy,
'
,FALSE);
$this->db->from("balances AS t1");
$this->db->join("customer AS t2","t2.CustomerId = t1.customer_id","left");
$this->db->join("gold_order AS t3","t3.CustomerId = t2.CustomerId","left");
$this->db->group_by("t3.CustomerId");
$object = $this->db->get();
< /code>
Результат: < /p>
< /p>
, что я хочу, чтобы быть count_sale. />
Подробнее здесь: https://stackoverflow.com/questions/392 ... ding-value