SQL 必知必会·笔记<3>过滤数据
在同时使用ORDER BY
和WHERE
子句时,应该让ORDER BY
位于 WHERE 之后,否则将会产生错误
WHERE子句操作符
范围值检查
使用BETWEEN
操作符,示例:
SELECT prod_name, prod_price FROM Products WHERE prod_price BETWEEN 5 AND 10;
2. 高级数据过滤
组合WHERE子句
AND操作符
WHERE 子句中的关键字,用来指示检索满足所有给定条件的行:
FROM Products WHERE vend_id = 'DLL01' AND prod_price <= 4;
OR操作符
WHERE子句中使用的关键字,用来表示检索匹配任一给定条件的行:
SELECT prod_name, prod_price FROM Products WHERE vend_id = 'DLL01' OR vend_id = ‘BRS01’;
IN操作符
WHERE 子句中用来指定要匹配值的清单的关键字,功能与OR 相当:
SELECT prod_name, prod_price FROM Products WHERE vend_id IN ( 'DLL01', 'BRS01' ) ORDER BY prod_name;
NOT操作符
WHERE 子句中用来否定其后条件的关键字:
SELECT prod_name FROM Products WHERE NOT vend_id = 'DLL01' ORDER BY prod_name;