where 常用条件范例
Sets the WHERE part of the query.
The method requires a $condition parameter, and optionally a $params parameter specifying the values to be bound to the query.
The $condition parameter should be either a string (e.g. 'id=1') or an array.
The $condition specified as an array can be in one of the following two formats:
- hash format:
['column1' => value1, 'column2' => value2, ...] - operator format:
[operator, operand1, operand2, ...]
A condition in hash format represents the following SQL expression in general: column1=value1 AND column2=value2 AND .... In case when a value is an array, an IN expression will be generated. And if a value is null, IS NULL will be used in the generated expression. Below are some examples:
['type' => 1, 'status' => 2]generates(type = 1) AND (status = 2).['id' => [1, 2, 3], 'status' => 2]generates(id IN (1, 2, 3)) AND (status = 2).['status' => null]generatesstatus IS NULL.
A condition in operator format generates the SQL expression according to the specified operator, which can be one of the followings:
and: the operands should be concatenated together using
AND. For example,['and', 'id=1', 'id=2']will generateid=1 AND id=2. If an operand is an array, it will be converted into a string using the rules described here. For example,['and', 'type=1', ['or', 'id=1', 'id=2']]will generatetype=1 AND (id=1 OR id=2). The method will not do any quoting or escaping.or: similar to the
andoperator except that the operands are concatenated usingOR. For example,['or', ['type' => [7, 8, 9]], ['id' => [1, 2, 3]]will generate(type IN (7, 8, 9) OR (id IN (1, 2, 3))).not: this will take only one operand and build the negation of it by prefixing the query string with
NOT. For example['not', ['attribute' => null]]will result in the conditionNOT (attribute IS NULL).between: operand 1 should be the column name, and operand 2 and 3 should be the starting and ending values of the range that the column is in. For example,
['between', 'id', 1, 10]will generateid BETWEEN 1 AND 10.not between: similar to
betweenexcept theBETWEENis replaced withNOT BETWEENin the generated condition.in: operand 1 should be a column or DB expression, and operand 2 be an array representing the range of the values that the column or DB expression should be in. For example,
['in', 'id', [1, 2, 3]]will generateid IN (1, 2, 3). The method will properly quote the column name and escape values in the range.To create a composite
INcondition you can use and array for the column name and value, where the values are indexed by the column name:['in', ['id', 'name'], [['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar']] ].You may also specify a sub-query that is used to get the values for the
IN-condition:['in', 'user_id', (new Query())->select('id')->from('users')->where(['active' => 1])]not in: similar to the
inoperator except thatINis replaced withNOT INin the generated condition.like: operand 1 should be a column or DB expression, and operand 2 be a string or an array representing the values that the column or DB expression should be like. For example,
['like', 'name', 'tester']will generatename LIKE '%tester%'. When the value range is given as an array, multipleLIKEpredicates will be generated and concatenated usingAND. For example,['like', 'name', ['test', 'sample']]will generatename LIKE '%test%' AND name LIKE '%sample%'. The method will properly quote the column name and escape special characters in the values. Sometimes, you may want to add the percentage characters to the matching value by yourself, you may supply a third operandfalseto do so. For example,['like', 'name', '%tester', false]will generatename LIKE '%tester'.or like: similar to the
likeoperator except thatORis used to concatenate theLIKEpredicates when operand 2 is an array.not like: similar to the
likeoperator except thatLIKEis replaced withNOT LIKEin the generated condition.or not like: similar to the
not likeoperator except thatORis used to concatenate theNOT LIKEpredicates.exists: operand 1 is a query object that used to build an
EXISTScondition. For example['exists', (new Query())->select('id')->from('users')->where(['active' => 1])]will result in the following SQL expression:EXISTS (SELECT "id" FROM "users" WHERE "active"=1).not exists: similar to the
existsoperator except thatEXISTSis replaced withNOT EXISTSin the generated condition.Additionally you can specify arbitrary operators as follows: A condition of
['>=', 'id', 10]will result in the following SQL expression:id >= 10.
where 常用条件范例的更多相关文章
- NSDate常用代码范例
NSDate常用代码范例 NSDate类用于保存时间值,同时提供了一些方法来处理一些基于秒级别时差(Time Interval)运算和日期之间的早晚比较等. 1. 创建或初始化可用以下方法 用于创建N ...
- SQL常用条件操作符
1.SQL的六类内容: (1)数据定义语言(DDL): 创建.删除表结构的语句,包括Create.Drop (2)数据控制语言(DCL): 为定义数据访问及修改权限而实现的语句,包括Grant.Rev ...
- 针对主流浏览器的CSS-HACK写法及IE常用条件注释
一.通用区分方式: IE6.IE7能识别*,标准浏览器(如FF)不能识别*:IE6能识别*,但不能识别 !important:IE7能识别*,也能识别 !important:IE8能识别\0,不能识别 ...
- SQL语句 常用条件判断
条件判断写法: 对每天记录执行操作时,判断所限制的条件-----> 操作符: = <>(不匹配检查) != &l ...
- Linux的iptables常用配置范例(1)
以下是来自 http://wiki.ubuntu.org.cn/IptablesHowTo 上的配置说明 可以通过/sbin/iptables -F清除所有规则来暂时停止防火墙: (警告:这只适合在没 ...
- shell中的常用条件判断
-e :该“文件名”是否存在.exit-d :该文件名是否为目录.dir-f :该文件名是否为普通文件.file -b:该文件是否为块文件.block -r :该文件是否具有可读属性 read-w ...
- Linux的iptables常用配置范例(2)
iptables -F #清除所有规则 iptables -X #清除所有自定义规则 iptables -Z #各项计数归零 iptables -P INPUT DROP #将input链 ...
- Linux的iptables常用配置范例(3)
编辑/etc/rc.local,加入iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth1 -j MASQUERADE,外网口eth1为dhc ...
- IOS正则表达式 (身份证、电话、汉字等常用条件筛选)
下面的正则列表 替换对应的正则规则 那个字符串就可以了 例如: //正则规则 NSString *regex = @"^((13[0-9])|(147)|(17[0-9])|(15[^ ...
随机推荐
- vs2015 c# winfrom应用程序打包成64位
关于Winform打包过程在网上已有详细教程,参考:https://www.cnblogs.com/yinsq/p/5254893.html 此次工作中需要打包成64位的程序,网上没有查到方法,现在讲 ...
- CPU、GPU、CUDA、cuDNN
CPU擅长逻辑处理控制,GPU适合高强度的并行计算任务,为什么会存在这种差别?今天搜集了些相关资料,摘抄总结如下. 一.什么是GPU GPU这个概念是由Nvidia公司于1999年提出的.GPU是显卡 ...
- java课堂笔记
- kd-tree题目总结
在竞赛中,kd-tree一般只用于平面,很少有高于二维的情况. 在随机情况下,kd-tree的复杂度为O(NlogN),但会被极端数据卡到平方级别. 总而言之,就是优美的暴力. 查询时,通过估价函数进 ...
- Lumen框架使用Redis与框架Cache压测比较
使用命令 ab -c 20000 -n 100000 'http://127.0.0.1:9050/v1/api.store.xxx'进行压测,并同时进行了交叉测试,结果如下: 高并发情况下数据目前没 ...
- onmouseover与onmouseenter区别
1.onmouseover.onmouseout:鼠标经过时自身触发事件,经过其子元素时也触发该事件:(父亲有的东西,儿子也有) ,支持冒泡 2.onmouseenter.onmouseleave:鼠 ...
- C语言采用socket实现http post方式上传json数据
1.按照HTTP协议发送请求: http POST 报文格式 http 报文是面向文本的. 报文分为:请求报文和响应报文 请求报文由:请求行,请求头部,空行和请求数据四个部分组成. <1.请求行 ...
- mysql 修改表字段长度
方案一: change ALTER TABLE t1 CHANGE a a VARCHAR(); change 可以用来更改字段名称和类型 ALTER TABLE table_name CHANGE ...
- 用usecase获取需求的方法是否有缺陷,还有什么地方需要改进
usecase的局限性 对于系统发展而言,Use Case的范围限制一个单一的系统,这是Use Cases最通常的形式,我们称之为System Use Case,它把整个系统看作是一个黑盒,它不指定任 ...
- SQLServer学习记录
use TestDataBase;go -- 派生表-- 第3页,每页5条数据select * from (select ROW_NUMBER() over(order by stuId) as nu ...