欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

《SQL必知必会》:高级数据过滤 WHERE AND OR IN NOT

程序员文章站 2022-05-03 13:17:10
...

1. AND操作符

-- AND操作符
SELECT
	prod_id,
	prod_price,
	prod_name 
FROM
	Products 
WHERE
	vend_id = '1001' 
	AND prod_price <= 10;

《SQL必知必会》:高级数据过滤 WHERE AND OR IN NOT

2. OR操作符

-- OR操作符
SELECT
	prod_name,
	prod_price 
FROM
	Products 
WHERE
	vend_id = '1001' 
	OR vend_id = 'ANV01';

《SQL必知必会》:高级数据过滤 WHERE AND OR IN NOT

3.组合使用OR和AND

-- 组合使用
SELECT 
	prod_name, 
	prod_price 
FROM 
	Products 
WHERE 
		( vend_id = '1001' OR vend_id = '1003' )
		AND prod_price >= 10;

《SQL必知必会》:高级数据过滤 WHERE AND OR IN NOT

4. IN操作符

-- IN操作符
SELECT
	prod_name,
	prod_price 
FROM
	Products 
WHERE
	vend_id IN ( '1001', '1002' ) 
ORDER BY
	prod_name;

《SQL必知必会》:高级数据过滤 WHERE AND OR IN NOT

5. NOT操作符

-- NOT操作符
SELECT
	prod_name 
FROM
	Products 
WHERE
	NOT vend_id = '1001' 
ORDER BY
	prod_name;

《SQL必知必会》:高级数据过滤 WHERE AND OR IN NOT