0

In this:

    $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);

I want select count(id) where order_status_history.new_status is a interval eg(2<=order_status_history.new_status<=6), no one single int. How make this in this sql?

2 Answers 2

2

As I Remember you can add Where statement as a string, like in a native sql query. Please, try this:

    $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');

Is This Working ?

0
2

What do you think about this:

$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);
1
  • using where_between to introduce the id interval!
    – deviloper
    Mar 5, 2013 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.