0
点赞
收藏
分享

微信扫一扫

MySQL-运算符

老王420 2022-01-26 阅读 36

MySQL-运算符

1、算数运算符

类别:+、-、*、/、%

-- 将每件商品价格+10
select pname,price+10 as new_price from product;
-- 将所有商品价格上调10%
select pname,price*1.1 as new_price from product;

2、比较运算符和逻辑运算符

等号

select * from product where pname='海尔洗衣机';
-- 查询价格为800的商品
select * from product where price=800;

不等于

-- 查询价格不是800的商品
select * from product where price!=800;
select * from product where price<>800;
select * from product where not (price=800);

>=、<=、>、<

-- 查询商品大于60的商品信息
select * from product where price>60;

-- 查询商品价格再200到1000的商品
select * from product where price between 200 and 1000;
select * from product where price>=200 and price<=1000;
select * from product where price>=200 && price<=1000;

-- 查询商品价格800或200的商品
select * from product where price in(800,200);
select * from product where price=800 or price=200;

模糊匹配like

-- 模糊匹配查询
-- 查询所有包含"裤"字的所有商品
select * from product where pname like '%裤%';  -- %可以匹配多个字符

-- 查询以"海"字开头的所有商品
select * from product where pname like '海%';

-- 查询第二个字为"寇"的商品
select * from product where pname like '_蔻%';  -- 下划线匹配一个字符

查询null和不是null

-- 查询category_id为null的商品
select * from product where category_id is null;

-- 查询category_id不为null的商品
select * from product where category_id is not null;

3、位运算

举报

相关推荐

0 条评论