mysql_where条件摘要

where字句中可以使用:

1. 比较运算符:> < >= <= <> !=
2. like 'egon%'
    pattern可以是%或_,
    %表示任意多字符
    _表示一个字符

1.单条件查询

//查询id大于7的记录。
select * from employee where id > 7
2.多条件查询

//查询post为'teacher' 并且 salary 大于8000的记录。
select * from employee where post = 'teacher' and salary > 8000;
3.关键字between and

//查询salary大于等于20000和salary小于等于30000的记录。
select * from employee where salary between 20000 and 30000;
4.in

//查询age为73或81或28的记录。
select * from employee where age in (73,81,28);
5.判断记录是否为NULL

//查询post_comment字段为null的记录。
select * from employee where post_comment is null;
//查询post_comment字段不为null的记录。
select * from employee where post_comment is not null;
6.like(%:匹配任意多个字符。_:匹配任意一个字符)

//查询name字段为"jin"开头的记录。
select * from employee where name like 'jin%';
//查询name字段为"ao"结尾的记录。
select * from employee where name like '%ao';
//查询name字段为"jin"开头后面有任意3个字符的记录。
select * from employee where name like 'jin___';
 7.正则表达式

//查询name字段以al开头的记录。
SELECT * FROM employee WHERE name REGEXP '^al';

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值