mysql过滤数据_MySQL过滤数据

1. MySQL过滤数据

使用where子句

select prod_name, prod_price from products where prod_price = 2.50;

检查单个值

select prod_name, prod_price from products where prod_name = 'fuses';

select prod_name, prod_price from products where prod_price < 10;

select prod_name, prod_price from products where prod_price <= 10;

不匹配检查

select vend_id, prod_name from products where vend_id <> 1003;

select vend_id, prod_name from products where vend_id != 1003;

范围值检查

select prod_name, prod_price from products where prod_price between 5 and 10;

空值检查

select cust_id from customers where cust_email is null;

1. where 执行匹配时默认不区分大小写

2. is null 判断空值

2. MySQL数据过滤

组合where子句

AND操作符

select prod_id, prod_price, prod_name from products where vend_id = 1003 and prod_price <= 10;

OR操作符

select prod_name, prod_price, vend_id from products where vend_id = 1002 or vend_id = 1003;

计算次序

select prod_name, prod_price, vend_id from products where vend_id = 1002 or vend_id = 1003 and prod_price >= 10;

IN操作符

select prod_name, prod_price, vend_id from products where vend_id in (1002, 1003) order by prod_name;

NOT操作符

select prod_name, prod_price, vend_id from products where vend_id not in (1002, 1003) order by prod_name;

1. AND在计算次序中优先级高于OR

2. IN使用的好处

1) 语法清楚更直观

2) 计算次序更容易管理

3) 比or操作符执行快

4) 可以包含其他select语句,可以更动态地建立where子句

3. NOT关键字

not支持in、between、exists子句取反

3. MySQL用通配符进行过滤

LIKE操作符

百分号(%)通配符

%表示任何字符出现任意次数

select prod_id, prod_name from products where prod_name like '%anvil%';

select prod_id, prod_name from products where prod_name like 's%e';

下划线(_)通配符

_表示任何字符出现一次

select prod_id, prod_name from products where prod_name like '_ ton anvil';

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值