Yii2查询之where条件拼装
来源:互联网 发布:javascript 页面加载 编辑:程序博客网 时间:2024/05/31 19:14
熟悉Yii2的查询条件后,用Active Record查询数据非常方便。以下我们介绍where()方法当中,条件的拼装方式。#某个值为null,会用IS NULL来生成语句:['type' => 1, 'status' => 2] // 生成:(type = 1) AND (status = 2)['id' => [1, 2, 3], 'status' => 2] // 生成:(id IN (1, 2, 3)) AND (status = 2)['status' => null] // 生成:status IS NULL['NOT', ['type' => null]]// 生成:type IS NOT NULL#对比['>', 'id', 1] // 生成:id > 1['<', 'id', 100] // 生成:id < 100['=', 'id', 10] // 生成:id = 10['>=', 'id', 1] // 生成:id >= 1['<=', 'id', 100] // 生成:id <= 100['!=', 'id', 10] // 生成:id != 10['and', 'id' => 1, 'id' => 2] // 生成:id=1 AND id=2['and', 'id=1', 'id=2'] // 生成:id=1 AND id=2['and', 'type=1', ['or', 'id=1', 'id=2']] // 生成:type=1 AND (id=1 OR id=2)['or', ['type' => [7, 8, 9]], ['id' => [1, 2, 3]]] // 生成:(type IN (7, 8, 9) OR (id IN (1, 2, 3)))['not', ['attribute' => null]] // 生成:NOT (attribute IS NULL)['between', 'id', 1, 10] // 生成:id BETWEEN 1 AND 10['not between', 'id', 1, 10] // 生成:id NOT BETWEEN 1 AND 10['in', 'id', [1, 2, 3]] // 生成:id IN (1, 2, 3)['id' => [4, 8, 15]] // 生成:id IN (4, 8, 15)['not in', 'id', [1, 2, 3]] // 生成:id NOT IN (1, 2, 3)['in', ['id', 'name'], [['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar']]] // 生成:(`id`, `name`) IN ((1, 'foo'), (2, 'bar'))#用子查询作为IN条件的值,如下:['in', 'user_id', (new Query())->select('id')->from('users')->where(['active' => 1])]['like', 'name', 'tester'] // 生成:name LIKE '%tester%'['like', 'name', ['test', 'sample']] // 生成:name LIKE '%test%' AND name LIKE '%sample%'['like', 'name', '%tester', false] // 生成:name LIKE '%tester' // 这是自定义查询方式,要传入值为false的运算数3,并且自行添加%['or like', 'name', ['test', 'sample']] // 生成:name LIKE '%test%' OR name LIKE '%sample%'['not like', 'name', 'tester'] // 生成:name NOT LIKE '%tester%'['or not like', 'name', ['test', 'sample']] // 生成:name NOT LIKE '%test%' OR name NOT LIKE '%sample%'['exists', (new Query())->select('id')->from('users')->where(['active' => 1])] // 生成:EXISTS (SELECT "id" FROM "users" WHERE "active"=1)来自:http://www.yiiframework.com/doc-2.0/yii-db-query.html#where()-detail
阅读全文
0 0
- Yii2查询之where条件拼装
- yii2查询条件Where全解析
- Yii2-条件Where使用说明
- js拼装查询条件字符串
- Jeecg 查询条件拼装-代码解读
- Jeecg 查询条件拼装-代码解读
- mybatis 拼装 and和or 查询条件
- 多where条件查询
- Yii2.0中文开发向导——查询条件Where全解析
- Yii2.0中文开发向导——查询条件Where全解析
- Yii2.0中文开发向导——查询条件Where全解析
- Yii2.0中文开发向导——查询条件Where全解析
- Yii2.0-advanced-10—数据库操作4(AR条件查询where)
- mysql中select 5种子句之where条件查询
- sql查询语句查询条件字段的拼装
- 查询条件与查询数据的ajax拼装
- where 条件查询 星等于
- rails 查询 where条件用法
- C#使用Capture摄像头
- 现代谱估计的参数模型
- 函数左括号到右括号跳转
- 微信分享链接后再次分享提示config:invalid signature
- node 代理 proxy
- Yii2查询之where条件拼装
- 多线程之ForkJoin框架
- 考研第一篇
- web前端笔记:url,href,src的区别
- 基于ionic2 的移动app开发过程《5》
- Docker容器技术进阶篇
- 2017.10.13 硬币游戏 思考记录
- JDK8使用Stream对数组合并、去重
- ArcGIS教程之DEM应用——水文分析