MySQL中【where】的使用

1、作用

where使用来过滤数据的,比如有以下查询语句

select name,age from user_message where age>=25

过滤出user_message 表里,age列大于等于25的列(name,price两列)

2、where子句的操作符
操作符说明举例
=等于Select name, price from products where prod_name = ‘fuses’
<>不等于Select id, name from products where id <> 1003
!=不等于
>大于/
>=大于等于/
<小于Select name, price from products where prod_price < ‘10’
<=小于等于Select name, price from products where prod_price < = ‘10’
between A and B在指定的两个值之间Select name, price from products where price between 5 and 10
is指定数值/检查空值Select id,name,price from products where name is null
like模糊查询 ,搜索匹配字段中的指定内容WHERE column LIKE pattern
not like模糊查询,搜索匹配字段中的指定内容WHERE column NOT LIKE pattern
andwhere子句组合操作符-并且where a=1 and B=2
orwhere子句组合操作符 -或者where a=1 or B=2
3、组合where子句

Mysql允许给出多个where子句,子句可以以两种方式使用;以and子句和or 子句的方式使用
(1)and操作符
取出表中id=1003和price< = 10;的数据

Select id, name, price, from products where id = 1003 and price < = 10

(2)or操作符
取出表中id id 等于1002,或id 等于1003的数据

Select id, name, price from products where id = 1002 or id = 1003

(3)计算次序
价格为10元以上,且有1002或1003的所有产品

select id,name,price from products where price>10 and(id=1002 or id=1003)

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值