MongoDB比较运算符用于测试等于或不等于,还有其它更高级的运算符。
在WHERE
子句中使用比较运算符来确定要选择的记录。以下是可以在MariaDB中使用的比较运算符的列表:
语法及示例 –
编号 | 比较运算符 | 描述 | 示例 |
---|---|---|---|
1 | = | 比较等于 | select * from students where id=100 |
2 | <=> | 比较等于(安全比较NULL 值) | select * from students where student_name<=>'Maxsu' |
3 | <> | 比较不等于 | select * from students where student_name<>'Maxsu' |
4 | != | 比较不等于 | select * from students where student_name!='Maxsu' |
5 | > | 比较大于 | select * from students where student_id>5 |
6 | >= | 比较大于或等于 | select * from students where student_id>=5 |
7 | < | 比较小于 | select * from students where student_id<5 |
8 | <= | 比较小于或等于 | select * from students where student_id<=5 |
9 | in ( ) | 匹配列表中的值 | select * from students where student_id IN(1,3,6) |
10 | not | 否定一个条件 | select * from students where student_id NOT IN(1,3,6) |
11 | between | 匹配在一个范围内(含) | select * from students where student_id between 1 AND 3) |
12 | is null | 判断是否为NULL 值 | select * from students where student_address IS NULL |
13 | is not null | 判断是否为非NULL 值 | select * from students where student_address IS NOT NULL |
14 | like | 与% 和_ 模式匹配 | select * from students where student_name LIKE 'Ma%' |
15 | exists | 如果子查询返回至少一行,则满足条件。 | — |