第七章:数据过滤
P43
select prod_id,prod_price,prod_name from products where vend_id =1003 and prod_price <=10; #检索vend_id=1003 并且prod_price<=10 #
select prod_name,prod_price from products where vend_id=1002 or vend_id =1003; #检索的条件只要满足vend_id=1002 ,vend_id=1003即可#
P42
select prod_name,prod_price from products where vend_id =1002 or vend_id=1003 and prod_price >=10;#and和or同时存在的时候,优先处理and的操作符,理解为两个条件:(vend_id=1002) or(vend_id =1003 and prod_price) ,满足其一即可。
P42
select prod_name,prod_price from products where (vend_id =1002 or vend_id =1003 ) and prod_price>=10; #执行两个命令:(vend_id=1002,vend_id=1003)和prod_price>=10,圆括号()的命令优先级高于and和or #
P43 in操作符 (in取合法值有逗号分开,如(5,8) )
select prod_name,prod_price from products where vend_id in (1002,1003) order by prod_name; #检索的条件vend_id 在1002到1003这个范围内#因为vend_id都是整数,所以上面的语句的结果和这个一样:
select prod_name,prod_price from products where vend_id=1002 or vend_id=1003 order by prod_name;
但注意,in命令比or执行更快。
P45
select prod_name,prod_price from products where vend_id not in (1002,1003) order by prod_name; #not否定了not后面的条件,不检索(1002,1003) #
原文地址:https://www.cnblogs.com/qiyuanjiejie/p/9392389.html