第五课 高级数据过滤

5.1 组合where字句

and的用法,用于组合多个where条件,比如返回:也可以在最后加入order by

select * from products where vend_id = 'BRS01' AND prod_price > 10

 or的用法:满足一个或者两个条件

select * from products where vend_id = 'BRS01' or prod_price > 10

or and混用过程中要注意,SQL中默认and的优先级比较高,所以会被错误的组合,所以最好用括号形式组合起来,也更容易阅读

select * from products where vend_id = 'BRS01' or vend_id = 'BRS02' and prod_price > 10;
select * from products where (vend_id = 'BRS01' or vend_id = 'BRS02') and prod_price > 10

 

 

5.2 in操作符

IN 操作符用来指定条件范围,范围中的每个条件都可以进行匹配。 IN 取一组由逗号分隔、括在圆括号中的合法值。类似完成了or的操作

select * from products where vend_id in ('BRS01','DLL01')

 

 

5.3 not操作符

否定其后所跟的任何条件。这两个其实是一样的

select * from products where not vend_id in ('BRS01','DLL01');
select * from products where vend_id not in ('BRS01','DLL01')

 

 

5.4 小结

了解and,or,in,not用法

 

posted @ 2018-03-24 09:56  慢慢来会比较快  阅读(124)  评论(0编辑  收藏  举报