0

在这:

    $this->db->select('count(o.id)');
    $this->db->from('orders o');           
            $this->db->join('order_status_history', 'o.id =  order_status_history.order_id');
            $this->db->where("(order_status_history.in_dts)::date ='" .$reportDay. "'");
            $this->db->where('order_status_history.new_status ' , 6);

我想要选择计数(id),其中 order_status_history.new_status 是一个间隔,例如(2<=order_status_history.new_status<=6),没有一个整数。如何在这个sql中做到这一点?

4

2 回答 2

2

我记得您可以将 Where 语句添加为字符串,就像在本机 sql 查询中一样。请试试这个:

    $this->db->select('count(o.id)');
    $this->db->from('orders o');           
        $this->db->join('order_status_history', 'o.id =  order_status_history.order_id');
        $this->db->where("(order_status_history.in_dts)::date ='" .$reportDay. "'");
        $this->db->where('order_status_history.new_status BETWEEN 2 AND 6');

这管用吗 ?

于 2013-03-05T09:15:41.840 回答
2

你怎么看待这件事:

$this->db->select('count(o.id)');
$this->db->from('orders as o');           
$this->db->join('order_status_history', 'o.id =  order_status_history.order_id');
$this->db->where("(order_status_history.in_dts)::date ='" .$reportDay. "'");
$this->db->where_between('order_status_history.new_status ',2 , 6);
于 2013-03-05T09:16:06.200 回答