文章目录[x]
- 1:DQL语言
- 1.1:基础查询
- 1.2:条件查询
- 1.3:模糊查询
- 1.4:排序查询
数据库
DQL语言
基础查询
表名(Mroot)
字段(m1,m2,m3...)
查询表中单个字段
select m1 from Mroot
查询表中多个字段
select m1,m2,m3 from Mroot
查询表中所有字段
select * from Mroot
(显示字段顺序和表中一样)
查询函数表达式
select version()
去重查询
select distinct m1 from Mroot
字段拼接
select concat(m1,m2) As 结果 from Mroot
条件查询
select * from Mroot where 条件
模糊查询
like一般配合通配符一起使用
通配符:
% 任意多个字符,包含0个字符
select * from Mroot where m1 like '%a%';
_ 任意单个字符
查找第三个字符为n第五个字符为k的
select * from Mroot where m1 like '__n_k%';
转义函数escape,对¥符号进行转义
select * from Mroot where m1 like '__$_k%' escape '$';
范围查询
查询a在100至200之间数据
select * from Mroot where a between 100 and 200;
in查询
m1字段中是否有等于a或者b或者c的数据
要求和字段数据类型一致
select * from Mroot where m1 in('a','b','c');
is null和is not null
安全等于<=>
排序查询
desc降序a,asc为升序
select * from Mroot order by m1 desc