Select name, price from products where price = 2.50;过滤出products表里price列等于2.50的列(name,price两列)sql
操做符spa |
说明ci |
=产品 |
等于table |
< >im |
不等于数据 |
!=tab |
不等于错误 |
<ab |
小于 |
< = |
小于等于 |
> |
大于 |
> = |
大于等于 |
BETWEEN |
在指定的两个值之间 |
Select name, price from products where prod_name = ‘fuses’;按name等于fuses,输出(name,price两个列,MySQL执行是不区分大小写)
Select name, price from products where prod_price < ‘10’;按price小于10的列,输出(name,price两个列,MySQL执行是不区分大小写)
Select name, price from products where prod_price < = ‘10’;按price小于等于10的列,输出(name,price两个列,MySQL执行是不区分大小写)
6.2.2不匹配检查
排除供应商编号为1003制造的全部产品
Select id, name from products where id < > 1003;
6.2.3范围值检查
Select name, price from products where price between 5 and 10;按price列取出5到10之间的name,price两列内容
#注:between操做符须要用两个值(低端值和高端值),切必须用and想连
6.2.4空值检查
检查表里name列为空的列
Select id, name, price from products where name is null;
Mysql容许给出多个where子句,子句能够以两种方式使用;以and子句和or 子句的方式使用
取出表中id=1003和price< = 10;的数据
Select id, name, price, from products where id = 1003 and price < = 10;
取出表中id id 等于1002,或id 等于1003的数据
Select id, name, price from products where id = 1002 or id = 1003;
价格为10元以上,且有1002或1003的全部产品
错误的SQL:
Select name, price, from produtes where id = 1002 or id = 1003 and price > = 10;
#由于优先级问题(and优先级大于or的优先级)
正确的SQL:
#注:()的优先级大于and,and的优先级大于or的优先级
Select name, price, from produtes where (id = 1002 or id = 1003) and price > = 10;
用来联络或改变where子句中的子句的关键字,也称为逻辑操做符。