select prod_id,prod_price from Products where prod_price = 3.49;
检索products表中两个列,只返回prod_price值等于3.49的行。
注意:由于数据库软件的指定。结果可能是3.490,3.4900。
注意:并非所有数据库软件都支持所有操作符。
价格小于10的产品:
select prod_name, prod_price from Products where prod_price < 10;
id不是DLL01项:
select vent_id,prod_name from Products where vent_id <> ‘DILL01‘;
或
select vent_id,prod_name from Products where vent_id != ‘DILL01‘;
价格在5和10之间的所有产品:
select prod_name, prod_price from Products where prod_price between 5 and 10 ;
空值(null)
select cust_name from Customers where cust_email IS NULL;
AND操作符
select prod_id,prod_price,prod_name from Products where prod_id = ‘DLL01‘ and prod_price <=4;
同时满足prod_id等于DLL01和prod_price小于等于4。
OR操作符
select prod_id,prod_price,prod_name from Products where prod_id = ‘DLL01‘ or prod_price <=4;
相对于and操作符,只要满足其中一条就可以。
为了消灭歧义,在组合where子句中使用圆括号。如下两个语句有着截然不同的意思:
select prod_id,prod_price,prod_name from Products where (prod_id = ‘DLL01‘ or prod_id = ‘BRS01‘) and prod_price >= 10;
首先会过滤括号内的条件
select prod_id,prod_price,prod_name from Products where prod_id = ‘DLL01‘ or prod_id = ‘BRS01‘ and prod_price >= 10;
由于SQL语言优先处理AND操作符,所以结果就变成满足prod_id=‘DLL01’或者prod_id=‘BRS01’+ prod_price>=10
IN操作符
select prod_id,prod_price,prod_name from Products where vend_id IN (‘DLL01‘, ‘BRS01‘) order by prod_name;
NOT操作符
select prod_id,prod_price,prod_name from Products where not vent_id = ‘DLL01‘ order by prod_name;
也可以用<>,!=操作符,具体的看数据库软件的设置
原文:https://www.cnblogs.com/haoqirui/p/10352400.html