mysql逻辑运算符

1. AND

  逻辑与,且运算;

  如:select prod_name,prod_price from products where prod_name='1 ton anvil' AND prod_price <= 10.00

+-------------+------------+
| prod_name | prod_price |
+-------------+------------+
| 1 ton anvil | 9.99 |
+-------------+------------+
1 row in set (0.00 sec)

2. OR

  逻辑或,或运算;

  如:select prod_name,prod_price from products where prod_name='1 ton anvil' or prod_price <= 10.00;

+----------------+------------+
| prod_name      | prod_price |
+----------------+------------+
| .5 ton anvil   |       5.99 |
| 1 ton anvil    |       9.99 |
| Bird seed      |      10.00 |
| Carrots        |       2.50 |
| Fuses          |       3.42 |
| Oil can        |       8.99 |
| Sling          |       4.49 |
| TNT (1 stick)  |       2.50 |
| TNT (5 sticks) |      10.00 |
+----------------+------------+
9 rows in set (0.00 sec)

 

3. NOT

  逻辑非。非运算;

   如,select prod_name,prod_price from products where NOT prod_name='1 ton anvil';

+----------------+------------+
| prod_name      | prod_price |
+----------------+------------+
| .5 ton anvil   |       5.99 |
| 2 ton anvil    |      14.99 |
| Detonator      |      13.00 |
| Bird seed      |      10.00 |
| Carrots        |       2.50 |
| Fuses          |       3.42 |
| JetPack 1000   |      35.00 |
| JetPack 2000   |      55.00 |
| Oil can        |       8.99 |
| Safe           |      50.00 |
| Sling          |       4.49 |
| TNT (1 stick)  |       2.50 |
| TNT (5 sticks) |      10.00 |
+----------------+------------+
13 rows in set (0.00 sec)

4. IN

  指定条件范围内的数据

  如:select prod_name,prod_price from products where prod_name in ('1 ton anvil', '2 ton anvil');

+-------------+------------+
| prod_name   | prod_price |
+-------------+------------+
| 1 ton anvil |       9.99 |
| 2 ton anvil |      14.99 |
+-------------+------------+
2 rows in set (0.00 sec)

 注意:存在混合逻辑运算时,应该使用括号进行限定;

posted @ 2021-04-22 15:31  唯一诺  阅读(343)  评论(0编辑  收藏  举报