where + and or in not
- select prod_name,prod_price from product where vend_id = ‘dell01’ and prod_price<5000;
- select prod_name,prod_price from product where vend_id = ‘DEL01’ or vend_id = ‘HUA01’;
- select prod_name,prod_price from product where (vend_id = ‘DEL01’ or vend_id = ‘HUA01’ ) and prod_price<5000; and 的优先级高于or,如果不加括号,则会筛选出价格小于5000的品牌名称为HUA01的产品及全部品牌名为DEL01的产品。加括号后筛选结果为HUA01及DEL01两个品牌价格小于5000产品。
- select prod_name,prod_price from product where vend_id in ( ‘DEL01’ ,‘HUA01’);where语句中的 in 用来指定范围,范围中的所有值均可进行匹配。in操作符的功能or也可完成。但in 更清楚简洁。
- select prod_name,prod_price from product where not vend_id = ‘DEL01’ order by prod_name;
where 语句中的not用来否定其后跟的所有条件。
《SQL必知必会》-学习记录。