MySql必知必会教程--数据过滤

select prod_id,prod_name,prod_price from products where vend_id = 1003 and prod_price <= 10;
输出结果:
+---------+----------------+------------+
| prod_id | prod_name      | prod_price |
+---------+----------------+------------+
| FB      | Bird seed      |      10.00 |
| FC      | Carrots        |       2.50 |
| SLING   | Sling          |       4.49 |
| TNT1    | TNT (1 stick)  |       2.50 |
| TNT2    | TNT (5 sticks) |      10.00 |
+---------+----------------+------------+

or操作符

select vend_id,prod_name,prod_price from products where (vend_id = 1002 or vend_id = 1003) and prod_price <= 10;
输出结果:
+---------+----------------+------------+
| vend_id | prod_name      | prod_price |
+---------+----------------+------------+
|    1003 | Bird seed      |      10.00 |
|    1003 | Carrots        |       2.50 |
|    1002 | Fuses          |       3.42 |
|    1002 | Oil can        |       8.99 |
|    1003 | Sling          |       4.49 |
|    1003 | TNT (1 stick)  |       2.50 |
|    1003 | TNT (5 sticks) |      10.00 |
+---------+----------------+------------+

in操作符

 select vend_id,prod_name from products where vend_id in(1002,1003) order by prod_name;
输出结果:
+---------+----------------+
| vend_id | prod_name      |
+---------+----------------+
|    1003 | Bird seed      |
|    1003 | Carrots        |
|    1003 | Detonator      |
|    1002 | Fuses          |
|    1002 | Oil can        |
|    1003 | Safe           |
|    1003 | Sling          |
|    1003 | TNT (1 stick)  |
|    1003 | TNT (5 sticks) |
+---------+----------------+

not in操作符

select vend_id,prod_name from products where vend_id not in(1002,1003) order by prod_name;
输出结果:
+---------+--------------+
| vend_id | prod_name    |
+---------+--------------+
|    1001 | .5 ton anvil |
|    1001 | 1 ton anvil  |
|    1001 | 2 ton anvil  |
|    1005 | JetPack 1000 |
|    1005 | JetPack 2000 |
+---------+--------------+

 

posted @ 2023-06-11 21:45  99号的格调  阅读(10)  评论(0编辑  收藏  举报