在此:
$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),没有一个单一的 int。如何在这个 sql 中做这个?
最佳答案
据我所知,您可以将 Where 语句添加为字符串,就像在 native 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');
这行得通吗?
关于php - 从子句为间隔的表中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15219753/