->where('orders.date_paid', 'BETWEEN', array($from, $to))
->and_where('orders.status', '=', 'new')
->or_where('orders.status', '=', 'delivered')
我想显示 date_paid 在 $from 和 $to 之间的所有行,其中状态为新的或已交付。
当我添加这个 or_where() 时,它会忽略 BETWEEN $from 和 $to date_paid where 子句。
我怎样才能正确地做到这一点?
最佳答案
您需要对您的条件进行分组。
->where('orders.date_paid', 'BETWEEN', array($from, $to))
->and_where_open()
->where('orders.status', '=', 'new')
->or_where('orders.status', '=', 'delivered')
->and_where_close();
关于Kohana 查询生成器 : and or where clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7987327/