第七章:数据过滤
这是《MySQL必知必会》的学习笔记,也是mysql的基础知识,以备以后方便查阅
-
MySQL数据库安装和练习数据导入,参考这篇ubuntu18安装mysql和导入练习数据
-
操作符的概念
- 用来联结或改变where子句中的子句的关键字
-
MySQL中的操作符
- and操作符 where子句中用来检索满足所有给定条件的行
select vend_id, prod_id, prod_price, prod_name from products where vend_id=1003 and prod_price<=10;
- or操作符 where子句中检索匹配任一给定条件的行
select vend_id, prod_name, prod_price from products where vend_id=1002 or vend_id=1003;
- in操作符 where子句中用来指定条件范围,范围中的每个条件都可以进行匹配,in操作符一般比or操作符清单执行更快
select vend_id, prod_name, prod_price from products where vend_id in (1002, 1003) order by prod_name;
- not操作符 where子句中用来否定后跟条件的关键字,MySQL支持使用not对in、between和exists子句(返回一个布尔值)取反
select vend_id, prod_name, prod_price from products where vend_id not in (1002,1003) order by prod_name; select prod_name, prod_price from products where prod_price not between 5 and 10 order by prod_price; select prod_name, prod_price from products where not exists(select count(*) from products);
- and操作符 where子句中用来检索满足所有给定条件的行
-
and和or操作符结合实现复杂查询,都应该使用()明确分组操作符,MySQL默认and操作符比or操作符优先级高
select vend_id, prod_name, prod_price from products where vend_id=1002 or vend_id=1003 and prod_price>=10; select vend_id, prod_name, prod_price from products where (vend_id=1002 or vend_id=1003) and prod_price>=10;
我在想我要不要写一句励志的话......