mysql基本的查询语句总结

本文详细介绍了SQL查询的基础与高级技巧,包括全表查询、部分字段查询、条件筛选、模糊匹配、范围查找及空值判断等操作,适用于数据库管理和数据分析人员提升技能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.查看表中所有信息

select * from 表名;

2.查看表中部分信息

select 字段1,字段2… from 表名;

3.使用 where 语句选择

select * from 表名 where 条件;

(1)比较运算符

等于: =
大于: >
大于等于: >=
小于: <
小于等于: <=
不等于: != 或 <>

(2)逻辑运算符

and
or
not

4.模糊查找
(1)like
%表示任性个任意字符
_ 下划线表示任意一个字符

select * from 表名 where 字段名 like 条件;

(2)rlike

select * from 表名 where 字段名 rlike 正则表达式;

5.范围查找
(1)in not in
in表示在一个非连续的范围内

select * from where 字段 in (value1, value2…);

not in 不在括号值内。

select * from where 字段 not in (value1, value2…);

(2)between … and …在一个连续的范围内

select * from where 字段 between value1 and value2;
查找在值1到值2的数据

not between … and …不在这个连续的范围内

select * from where 字段 not between value1 and value2;
查找不在值1到值2的数据

这里注意 not in 与 not between 是一个整体语句,而一个not表示对某个条件的否定。
例如;

select * from where 字段 not between value1 and value2;
相当于:
select * from where not 字段 between value1 and value2;

(3) is null 判断为null
is not null 判断不为null

select * from where 字段 is null;
查找字段为空的数据

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值