4、数据过滤

组合where子句以建立功能更加强大的更高级的搜索条件,并使用not和in操作符。

一、组合where子句

MySQL允许给出多个where子句,这些子句可以使用:以and子句的方式或or子句的方式使用。

1.1 and操作符

select prod_id, prod_price, prod_name from products where vend_id = 1003 and prod_price <=10;

1.2 or操作符

select vend_id, prod_price, prod_name from products where vend_id = 1003 or vend_id = 1002;

1.3 计算次序

在where子句中使用圆括号,任何时候使用具有and和or操作符的where子句,都应该使用圆括号明确地分组操作符,不要过分依赖默认计算次序,(and操作符优先级高于or)。

select vend_id, prod_price, prod_name from products where vend_id = 1002 or vend_id = 1003 and prod_price >=10;(会查询出vend_id为1002但是prod_price小于10的数据)

select vend_id, prod_price, prod_name from products where (vend_id = 1002 or vend_id = 1003) and prod_price >=10;

二、in操作符

select vend_id, prod_price, prod_name from products where vend_id in (1002, 1003)

三、not操作符

select vend_id, prod_price, prod_name from products where vend_id not in (1002, 1003)

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值