如何使用函数计算mysql表的两列之和?如下
在“订单”列2的两个列中添加值,在列1“小计”的列2“描述”中如何将两列求和?
公共函数count_gainliquid(){// Ganho Liquido
$this->ci->db->where('status', '1');
$count = $this->ci->db->get('orders');
$processbar = (1000 * $count->num_rows());
$total = 0;
foreach ($count->result() as $row) {
$this->ci->db->where('id', $row->id);
$orders = $this->ci->db->get('orders');
if ($orders->num_rows() > 0) {
foreach ($orders->result() as $ord) {
$total += $ord->subtotal;
}
}
}
return json_decode(json_encode(array('processbar' => $processbar, 'count' => $count->num_rows(), 'total' => number_format($total, 2, ",", ".") )));
}