简体   繁体   English

从表中选择,其中子句是间隔

[英]Select from table where clause is interval

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. 我想选择count(id),其中order_status_history.new_status是一个区间,例如(2 <= order_status_history.new_status <= 6),没有一个整数。 How make this in this sql? 如何使这个SQL?

As I Remember you can add Where statement as a string, like in a native sql query. 我记得您可以将Where语句添加为字符串,就像在本地sql查询中一样。 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 ? 这管用吗 ?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM