mysql逻辑运算符

2021/4/22 19:25:56

本文主要是介绍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)

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



这篇关于mysql逻辑运算符的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程