我想问你们中是否有人知道如何在编码点火器中放置or_where?
我想创建一个如下所示的查询
select *
from table
where
(
(in = 0 and call_in = 1) or
(out = 0 and call_out = 1)
) and
mid = 0
ORDER BY id DESC
limit 1
我创造了这样的东西
$result = $mysql_handler->select('*')
->from("table")
->where(
array(
"in" => 0,
"call_in" => 1
)
)
->or_where(
array(
"out" => 0,
"call_out" => 1
)
)
->where("mid", 0)
->order_by("id", "DESC")
->limit(1)
->get();
但我知道这是不对的,因为这段代码会产生这样的东西
select *
from table
where
(in = 0 and call_in = 1) or
(out = 0 and call_out = 1) and
mid = 0
ORDER BY id DESC
limit 1
我想将or_where放在 where 子句中,但我不确定这是否正确或如何做到这一点。请指教谢谢。
您不能根据需要组合where
和or_where
。 or_where
可用于只需要OR
查询的情况。您可以为您的解决方案尝试此操作
$this->db->from('table');
$this->db->select('*');
$this->db->where('((in = 0 and call_in = 1) OR (out = 0 and call_out = 1))');
$this->db->where("mid", 0);
$this->db->order_by("id", "DESC");
$this->db->limit(1);
$result=$this->db->get();
或
$result = $mysql_handler->select('*')
->from("table")
->where('((in = 0 and call_in = 1) OR (out = 0 and call_out = 1))')
->where("mid", 0)
->order_by("id", "DESC")
->limit(1)
->get();