我有一个这样的数据库
order_id | date               | qty
------------------------------------
a        |2018-11-11 10:03:33 |1
b        |2018-11-12 10:03:33 |1
c        |2018-11-11 12:03:33 |1我有一个这样的模型,
public function get_total_sales_per_day($date_from, $date_to)
{    
    $this->db->select('order_id, SUM(qty) as total, date');
    $this->db->from("order");
    $this->db->group_by('date');
    $this->db->order_by('date','asc');
    $query = $this->db->get();
    log_message("debug", $this->db->last_query());
    return $query->result();
}如何仅从年、月、日使用group_by date?
发布于 2019-08-02 19:22:29
如果只想像(y-m-d)那样按日期分组,则不按时间应用分组
然后在代码中进行一些更改,如:
在您的代码中进行一些修改
public function get_total_sales_per_day($date_from, $date_to)
{    
    $this->db->select('order_id, SUM(qty) as total, date');
    $this->db->from("order");
    $this->db->group_by(DATE_FORMAT('date', "%y-%y-%d"));
    $this->db->order_by('date','asc');
    $query = $this->db->get();
    log_message("debug", $this->db->last_query());
    return $query->result();
}https://stackoverflow.com/questions/57323949
复制相似问题