数学符号包括:
> , < , = , <=, >= , >< (不等于)
select
purchase_price
from
product
where
purchase_price = 500; -- 这里的500 也可以是字符
between 边界1 and 边界2 ;
注意:包含边界
select
purchase_price
from
product
where
purchase_price between 790 and 2800;
查询表格为空的记录
select
product_name,
product_type,
purchase_price
from
product
where
purchase_price is null;
使用逻辑运算可以限制过个条件
select
product_name,
product_type,
purchase_price
from
product
where
(purchase_price is null) and (product_type = '厨房用具');
select
product_name,
product_type,
purchase_price
from
product
where
(purchase_price is null)
or (product_type = '厨房用具');
适当的使用括号,可以避免逻辑运算符的错误。
select
product_name,
product_type,
purchase_price
from
product
where
(purchase_price is null)
or (product_type = '厨房用具'
and purchase_price between 790 and 2800);
找出和条件不匹配的记录
select
product_name,
product_type,
purchase_price
from
product
where
not product_type in ( '厨房用具');
in 表示我们限制了要使用哪些数据; in 后面的内容用 小括号括起来
select
product_name,
product_type,
purchase_price
from
product
where
product_name in ('菜刀', '叉子');
select
product_name,
product_type,
purchase_price
from
product
where
product_name in (
select
product_name
from
product
where
product_type in ('厨房用具')
);
select
product_name,
product_type,
purchase_price
from
product
where
product_name like '%T恤';
通配符说明:
% 可以匹配满足条件的所有字符,只要存在就输出
_ 下划线,仅仅匹配单个字符,几个下划线就匹配几个字符;
注意:
通配符不能匹配 null
举例1:
select
product_name,
product_type,
purchase_price
from
product
where
product_name regexp '^T恤'; -- 查询以T恤开头的信息
select
product_name,
product_type,
purchase_price
from
product
where
product_name regexp '^[^[T恤]]'; -- 查询不以这个开头的信息