第五章 高级数据过滤

本章介绍组合WHERE子句以建立更高级的搜索条件,以及NOT和IN操作符
1. 操作符(operator) 用来联结或改变WHERE子句中的子句的关键字,也称为逻辑操作符(logical operator)

2. AND操作符
SELECT prod_id, prod_price, prod_name
FROM Products
WHERE vend_id = 'DLL01' AND prod_price <= 4;

3. OR操作符
SELECT prod_price, prod_name
FROM Products
WHERE vend_id = 'DLL01' OR vend_id = 'BRS01';

4. 计算次序
AND优先级高于OR,改变次序要加()

5. IN操作符
SELECT prod_price, prod_name
FROM Products
WHERE vend_id IN ('DLL01', 'BRS01')
ORDER BY prod_name;

6. NOT操作符
SELECT prod_name
FROM Products
WHERE NOT vend_id = 'DLL01'//或者写为:vend_id <> 'DLL01'
ORDER BY prod_name;

注意:MYSQL中不支持这里描述的NOT,在MYSQL中,NOT只用来否定EXISTS(如NOT EXISTS)

你可能感兴趣的:(《SQL必知必会》学习笔记)