Rumah > pembangunan bahagian belakang > tutorial php > 有关zentaophp框架的一个sql语句方法

有关zentaophp框架的一个sql语句方法

WBOY
Lepaskan: 2016-07-06 13:54:16
asal
1385 orang telah melayarinya

<code>php</code><code>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();  
</code>
Salin selepas log masuk
Salin selepas log masuk

这段代码能够生成这样的sql

<code>sql</code><code>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
</code>
Salin selepas log masuk
Salin selepas log masuk

对上面的orm语句如何书写才能形成下列的SQL语句

<code>sql</code><code>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
</code>
Salin selepas log masuk
Salin selepas log masuk

简单说明就是在begin和end两个where条件外面加上括号该怎么处理?

回复内容:

<code>php</code><code>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();  
</code>
Salin selepas log masuk
Salin selepas log masuk

这段代码能够生成这样的sql

<code>sql</code><code>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
</code>
Salin selepas log masuk
Salin selepas log masuk

对上面的orm语句如何书写才能形成下列的SQL语句

<code>sql</code><code>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
</code>
Salin selepas log masuk
Salin selepas log masuk

简单说明就是在begin和end两个where条件外面加上括号该怎么处理?

Label berkaitan:
php
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan