数据过滤

2019-08-05  本文已影响0人  骑着白龙马的猪八戒

where、and、or

AND:  必须满足and前后所有的条件

select prod_id,prod_price,prod_name from products where vend_id = 1003 order by prod_price;

select prod_id,prod_price,prod_name from products where vend_id = 1003 and prod_price <= 10 order by prod_price;

OR:满足or 前后任意一个条件即可

select vend_id prod_id,prod_price,prod_name from products where vend_id = 1003 or prod_price <= 10 order by prod_price;

where语句中同时有and和or时,优先处理and

select prod_name,prod_price,vend_id from products where prod_price >= 10 and vend_id = 1003 or vend_id = 1002;

select prod_name,prod_price,vend_id from products where prod_price >= 10 and vend_id = 1002 or vend_id = 1003;

sql语句允许使用()来凸显优先级

select prod_name,prod_price,vend_id from products where prod_price >= 10 and (vend_id = 1003 or vend_id = 1002)

    -> order by

    -> prod_price;

IN操作符

select prod_name,prod_price,vend_id from products where vend_id in (1003,1002) order by prod_name;

和 select prod_name,prod_price,vend_id from products where vend_id =1003 or vend_id = 1002 order by prod_name;效果相同,但是如果条件多点,用IN更方便;

NOT操作符    作用就是否定它之后的所有语句

select prod_name,prod_price,vend_id from products where vend_id not in (1003,1002) order by prod_name;

选择vend_id不是1002和1003的商品信息

上一篇下一篇

猜你喜欢

热点阅读