where子句的操作符如下
1.检查单个值
语句:select * from products where vend_id = 1002;
截图:
2.检查多个值
语句:select * from products where vend_id = 1002 and prod_price = 3.42;
截图:
解释:多个值之间用and, or 连接。
3.不匹配检查
语句:select * from products where vend_id != 1002 order by vend_id;
截图:
解释:在同时使用order by和where子句时,应该让order by位于where之后。
4.范围值检查
语句:select * from products where prod_price between 5 and 10 order by prod_price;
截图:
解释:查找范围时,用between and连接两个值。
5.空值检查
语句:select * from products where prod_price is null;
截图:
解释:价格为空是指没有价格,不是指价格为0.
6.in语句
语句:select * from products where vend_id in(1002, 1003);
截图:
解释:
in 和 or的效果一样
它们的区别是:
1.in操作符的语法更清晰更直观
2.在使用in操作符是,计算的次序更容易管理。
3.in操作符一般比or操作符执行更快。
4.in可以包含其他select语句,使得更动态地建立where子