mysql第七章课后答案_《mysql必知必会》学习_第七章_20180730_欢

第七章:数据过滤

P43

select prod_id,prod_price,prod_name from products where vend_id =1003 and prod_price <=10;  #检索vend_id=1003 并且prod_price<=10 #

5c8c1450b6bf3bb82e2de9683e804e94.png

select prod_name,prod_price from products where vend_id=1002 or vend_id =1003; #检索的条件只要满足vend_id=1002 ,vend_id=1003即可#

ffee3a7b8e58cb822e4bd99df45dcf45.png

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) ,满足其一即可。

771bbeaa209c50ccb57574ffa8ba562e.png

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 #

66ff22b07ec1fdae985797f81a4de897.png

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执行更快。

989a2cd3ea7f2c338c5904d214377882.png

P45

select prod_name,prod_price from products where vend_id not in (1002,1003) order by prod_name; #not否定了not后面的条件,不检索(1002,1003) #

63452d28d056dc122a2df6c8198bea4c.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值