MongoDB比較運(yùn)算符用于測試等于或不等于,還有其它更高級(jí)的運(yùn)算符。
在WHERE
子句中使用比較運(yùn)算符來確定要選擇的記錄。以下是可以在MariaDB中使用的比較運(yùn)算符的列表:
語法及示例 -
編號(hào) | 比較運(yùn)算符 | 描述 | 示例 |
---|---|---|---|
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 |
否定一個(gè)條件 | select * from students where student_id NOT IN(1,3,6) |
11 | between |
匹配在一個(gè)范圍內(nèi)(含) | 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 |
如果子查詢返回至少一行,則滿足條件。 | — |