我需要一个问题的帮助,有代码和总和,在这个总和之后,我需要实现另一个和得到的结果。
分组和求和后是否可以运行查询?我的代码:
$start = "2018-08-01";
$end = "2018-08-30";
$this->db->where("DATE(launched_on) BETWEEN DATE('".$start."') AND DATE('".$end."')");
$this->db->select("*,
payment_method,sum(value) as Total,
SUM(value * (REPLACE(comission, '1/', '') / 100)) as commission_new,
GROUP_CONCAT(id separator ';') as all_ids,
SUM(IF(received_employee = 'yes',
value * (REPLACE(comission, '1/', '') / 100) , 0)) as pay_value,
sum(amount) as Total_sale");
$this->db->group_by('order_id, product');
$this->db->where("type_transaction='products'");
$teste = $this->db->get_where('cashier_transaction',
array('company_id'=>"1",
'type_payment'=>'finish_order',
'type'=>'revenue',
'product'=>'1'))->result();
结果代码:
[0] => stdClass Object
(
[amount] => 1
[order_id] => 11307
[product] => 1
[payment_method] => 2
[Total] => 76
[commission_new] => 13.68
[all_ids] => 15242
[pay_value] => 13.68
[Total_sale] => 1
)
[1] => stdClass Object
(
[amount] => 1
[order_id] => 11402
[product] => 1
[payment_method] => 3
[Total] => 76
[commission_new] => 13.68
[all_ids] => 15350
[pay_value] => 13.68
[Total_sale] => 1
)
[2] => stdClass Object
(
[amount] => 1
[order_id] => 11536
[product] => 1
[payment_method] => 3
[Total] => 76
[commission_new] => 13.68
[all_ids] => 15532
[pay_value] => 13.68
[Total_sale] => 1
)
[3] => stdClass Object
(
[amount] => 1
[order_id] => 11546
[product] => 1
[payment_method] => 3
[Total] => 76
[commission_new] => 13.68
[all_ids] => 15549
[pay_value] => 13.68
[Total_sale] => 1
)
[4] => stdClass Object
(
[amount] => 1
[order_id] => 11616
[product] => 1
[payment_method] => 2
[Total] => 76
[commission_new] => 13.68
[all_ids] => 15637
[pay_value] => 13.68
[Total_sale] => 1
)
obs:我需要团体订单号,因为有多种付款方式。
我需要这个结果:(这将是所有值的总和“总计,佣金\新,支付\价值和一组产品”)
[0] => stdClass Object
(
[product] => 1
[Total] => 380
[commission_new] => 68.35
[all_ids] => 15837;15549;15532;15242
[pay_value] => 68.35
[Total_sale] => 5
)
有可能吗?
1条答案
按热度按时间vi4fp9gy1#
解决方案:
结果: