查询条件和排序规则
简介
本章主要介绍查询条件示例说明。
查询条件
| SQL关键字 | python语法示例 | SQL语句 | 备注 | 
| AND | $字段别名 = '内容' | where 字段别名 = '内容' | 单个条件 | 
| \$字段别名1 = '内容1' and \$字段别名2 = '内容2' | where 字段别名1 = '内容1'and 字段别名2 = '内容2' | 多个条件 | |
| OR | $字段别名 = '内容' | where 字段别名 = '内容' | 单个条件 | 
| $字段别名1 = '内容1' or $字段别名2 = '内容2' | where 字段别名1 = '内容1'or 字段别名2 = '内容2' | 多个条件 | |
| IN | $字段别名 in ('内容1','内容2','内容3') $字段别名 is null | where 字段别名 in ('内容1','内容2','内容3') where 字段别名 is null | IN的值可以为多个,使用数组表示 | 
| NOT IN | $字段别名 not in ('内容1','内容2','内容3') $字段别名 is not null | where 字段别名 not in ('内容1','内容2','内容3') where 字段别名 is not null | NOT IN的值可以为多个,使用数组表示 | 
| BETWEEN | $字段别名 between '内容1' and '内容2' | where 字段别名 between '内容1' and '内容2' | BETWEEN的值只能为2个,使用数组表示 (如果是数字字段则表示为数学值) | 
| NOT BETWEEN | $字段别名 not between '内容1' and '内容2' | where 字段别名 not between '内容1' and '内容2' | NOT BETWEEN的值只能为2个,使用数组表示 (如果是数字字段则表示为数学值) | 
| LIKE | $字段别名 like '%内容1%' | where 字段别名 like '%内容1%' | LIKE的值只能为1个,可以使用通配符% | 
| NOT LIKE | $字段别名 not like '%内容1%' | where 字段别名 not like '%内容1%' | NOT LIKE的值只能为1个,可以使用通配符% | 
排序规则
| SQL关键字 | python语法示例 | SQL语句 | 备注 | 
| ORDER BY | order by $字段别名 desc | order by 字段别名 desc | ORDER 对应的模式有倒序(desc)和正序(asc)两种 | 
| order by $字段别名1 desc, 字段别名2 asc | order by 字段别名1 desc, 字段别名2 asc | ORDER 操作的字段如果为数字则根据数学大小进行排序(注意按数字大小排序时需要在字段后面+0, 例如:order by $字段别名1+0 desc) | |
| GROUP BY | group by $字段别名1, $字段别名2 | group by 字段别名1, 字段别名2 | GROUP 支持多个字段,使用数组表示 | 
| LIMIT | limit 0, 500 | limit 0, 500 | LIMIT 的第1个参数为起始索引(从0开始)第2个参数为索引后面取出的数据条数(专用于select语句) | 
| limit 1 | limit 1 | 表示对结果集的前面1行数据生效(可用于update,delete语句) | 
