写数据库查询语句的时候,如果有两个where条件以or的关系并行,要怎么写
FROM zt_TASK
WHERE (assignedTo = 'admin'
OR mailto LIKE "%,admin%")
AND deleted = "0"
AND zt_TASK.status NOT IN ('closed', 'cancel')
您好,您这样查询看下呢
SELECT *
FROM zt_TASK
WHERE assignedTo = 'admin'
OR mailto LIKE "%,admin%"
AND deleted = "0"
AND zt_TASK.status NOT IN ('closed', 'cancel')
我的意思可能没表达清楚,我想要在代码中实现我上面写的sql语句
->where('assignedTo')->eq($this->app->user->account)
->orwhere('mailto')->like("%,{$this->app->user->account}%")
->andWhere('status')->notIN('cancel, closed')
->andWhere('deleted')->eq(0)
现在这样写,查出来的数据会少一条
您好,您这样查询看下呢
SELECT *
FROM zt_TASK
WHERE assignedTo = 'admin'
OR mailto LIKE "%,admin%"
AND deleted = "0"
AND zt_TASK.status NOT IN ('closed', 'cancel')
2种方案:
方案一:
$this->dao->query($sql)->fetch();用于查询数据
$this->dao->exec($sql);用于更新数据
方案二:
->where('status')->notIN('cancel, closed')
->andWhere('assignedTo',true)->eq($this->app->user->account)
->orwhere('mailto')->like("%,{$this->app->user->account}%")
->markRight(1);
->andWhere('deleted')->eq(0)