php - 从子句为间隔的表中选择

标签 php mysql codeigniter

在此:

    $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/

相关文章:

mysql - 错误 1044 (42000) : Access denied for 'root' With All Privileges

php - 使用 codeigniter 构建多语言站点的最佳方式?

PHP站点部署建议

mysql - 编写 ActiveRecord 查询

php - Codeigniter 关联数组 - 在 foreach 循环中更改数组名称

php - 通过PHP验证用户

javascript - codeigniter 未捕获类型错误 : Cannot use 'in' operator to search for 'length' in When theres additional segment

php - 从 Codeigniter 执行 Python 文件

php - 将来自 JSON 的数据放入 MySQL 数据库

php - 在 PHP 中安全地创建和销毁登录 session