如何在codeigniter数据库类中列的总和?

时间:2016-02-13 10:46:00

标签: php mysql codeigniter mysqli codeigniter-2

如果日期介于某个预定义日期之间,我想对列数据求和。

我这样做的核心php就像

SUM(IF(`trl`.`entrydate` between '2015-01-01' and '2015-01-31', `trl`.`itemvalue`, 0))

那我怎么能用codeigniter

来做呢

1 个答案:

答案 0 :(得分:2)

有活动记录:

    $this->db->select_sum('data');
    $this->db->where("entrydate between 'x' and 'y' ");
    $query = $this->db->get('your table');

查询:

$this->db->query("select SUM(data) from `your table` where entrydate between 'x' and 'y' ");