有关zentaophp框架的一个sql语句方法
程序员文章站
2022-04-19 17:55:33
...
php
return $this->dao->select('id,amount,dept,signedBy,begin,end,bourse,openBank')->from(TABLE_CONTRACT) ->where('deleted')->eq(0) ->beginIF($mode=='bysearch')->andWhere('begin','between',$startDate,$endDate) ->orWhere('end')->between($startDate,$endDate) ->fi() ->beginIF($dept) ->andWhere('dept')->eq($dept) ->fi() // ->groupBy($groupBy) ->orderBy($orderBy) ->fetchAll();
这段代码能够生成这样的sql
sql
SELECT id,amount,dept,signedBy,begin,end,bourse,openBank FROM `crm_contract` wHeRe deleted = '0' AND dept = '820011' AND begin BETWEEN '2015-03-01' AND '2015-03-31' OR end BETWEEN '2015-03-01' AND '2015-03-31' oRdEr bY `signedBy` desc,`amount` desc
对上面的orm语句如何书写才能形成下列的SQL语句
sql
id,amount,dept,signedBy,begin,end,bourse,openBank FROM `crm_contract` wHeRe deleted = '0' AND dept = '820011' AND (begin BETWEEN '2015-03-01' AND '2015-03-31' OR end BETWEEN '2015-03-01' AND '2015-03-31' ) oRdEr bY `signedBy` desc,`amount` desc
简单说明就是在begin和end两个where条件外面加上括号该怎么处理?
回复内容:
php
return $this->dao->select('id,amount,dept,signedBy,begin,end,bourse,openBank')->from(TABLE_CONTRACT) ->where('deleted')->eq(0) ->beginIF($mode=='bysearch')->andWhere('begin','between',$startDate,$endDate) ->orWhere('end')->between($startDate,$endDate) ->fi() ->beginIF($dept) ->andWhere('dept')->eq($dept) ->fi() // ->groupBy($groupBy) ->orderBy($orderBy) ->fetchAll();
这段代码能够生成这样的sql
sql
SELECT id,amount,dept,signedBy,begin,end,bourse,openBank FROM `crm_contract` wHeRe deleted = '0' AND dept = '820011' AND begin BETWEEN '2015-03-01' AND '2015-03-31' OR end BETWEEN '2015-03-01' AND '2015-03-31' oRdEr bY `signedBy` desc,`amount` desc
对上面的orm语句如何书写才能形成下列的SQL语句
sql
id,amount,dept,signedBy,begin,end,bourse,openBank FROM `crm_contract` wHeRe deleted = '0' AND dept = '820011' AND (begin BETWEEN '2015-03-01' AND '2015-03-31' OR end BETWEEN '2015-03-01' AND '2015-03-31' ) oRdEr bY `signedBy` desc,`amount` desc
简单说明就是在begin和end两个where条件外面加上括号该怎么处理?
推荐阅读
-
ThinkPHP3.2.3框架实现执行原生SQL语句的方法示例
-
ThinkPHP3.2.3框架实现执行原生SQL语句的方法示例
-
Laravel框架执行原生SQL语句及使用paginate分页的方法
-
Yii框架在页面输出执行sql语句以方便调试的实现方法
-
thinkPHP框架中执行原生SQL语句的方法
-
SQL Server使用一个语句块批量插入多条记录的三种方法
-
获取django框架orm query执行的sql语句实现方法分析
-
使用thikphp框架的,一个项目里面有多个文件夹,html页面放在哪个文件夹里,和Action文件夹里的方法怎么调用,特别是在调用时的路径有关问题,尽量详细
-
php CI框架关于同一个控制器不同方法的数据有关问题
-
php CI框架关于同一个控制器不同方法的数据有关问题